3 Replies Latest reply: Apr 23, 2012 8:41 AM by Wolf-Dieter Fink RSS

    Using system property expansion in datasource's driver node in JBoss 7 standalone.xml

    Shahin Askari Newbie

      Hi guys,

       

      In JBoss 7.1.1.Final, in order to simplify switching between large number of test databases hosted on sybase and oracle, we would like to exeternalize the datasource configuration parameters.  We have attempted to use the system property expansion and it seems to work for most of the datasource configuration parameters except for the driver.  Can anyone point us in the right direction?

       

      This is a snippit out of our standalone.xml:

       

       

      <datasource jndi-name="java:/test/datasources/TestDS" pool-name="TestDS" spy="true">
                          <connection-url>${test.db.url}</connection-url>
                          <driver>${test.db.driver}</driver>
                          <security>
                              <user-name>${test.db.user}</user-name>
                              <password>${test.db.password}</password>
                          </security>
      </datasource>
      <drivers>
                          <driver name="sybase" module="com.sybase.jdbc">
                              ...
                          </driver>
                          <driver name="oracle" module="com.oracle.ojdbc6">
                              ...
                          </driver>
      </drivers>
      

       


       

      We would like to be able to start the server with  ./bin/startstandalone.sh -Dtest.db.driver=oracle -Dtest.db.... however, the driver variable doesnt seem to be expanded and the startup fails complaining about a missing driver named ${test.db.driver}.   Is there a way to switch the drivers at startup time?

        • 1. Re: Using system property expansion in datasource's driver node in JBoss 7 standalone.xml
          Wolf-Dieter Fink Master

          Looks like that the driver element supports the environment expansion but the dependency management ignore it.

          You see different messages if you set '-Dtest.db.driver=XX' or not.

           

          A workaround might be to create a standalone-<drivername>.xml for al different database types and start with the -c <standalone.xml name> option.

          • 2. Re: Using system property expansion in datasource's driver node in JBoss 7 standalone.xml
            Shahin Askari Newbie

            Here is a simple example using the default h2 datasource:

             

                        <datasources>
                            <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                                <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
                                <driver>${test.jdbc.driver}</driver>
                                <security>
                                    <user-name>sa</user-name>
                                    <password>sa</password>
                                </security>
                            </datasource>
                            <drivers>
                                <driver name="h2" module="com.h2database.h2">
                                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                                </driver>
                            </drivers>
                        </datasources>
            

             

             

            Here is output starting without any flags:

             

             

            $ ./bin/standalone.sh -c standalone.xml
            ...
            19:38:49,422 INFO  [org.jboss.modules] JBoss Modules version 1.1.1.GA
            19:38:49,562 INFO  [org.jboss.msc] JBoss MSC version 1.0.2.GA
            19:38:49,601 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting
            19:38:50,327 INFO  [org.xnio] XNIO Version 3.0.3.GA
            19:38:50,338 INFO  [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
            19:38:50,338 INFO  [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
            19:38:50,355 INFO  [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
            19:38:50,389 INFO  [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
            19:38:50,427 INFO  [org.jboss.as.connector] (MSC service thread 1-3) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
            19:38:50,440 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.
            19:38:50,463 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 44) JBAS013101: Activating Security Subsystem
            19:38:50,512 INFO  [org.jboss.as.configadmin] (ServerService Thread Pool -- 26) JBAS016200: Activating ConfigAdmin Subsystem
            19:38:50,527 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
            19:38:50,557 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem
            19:38:50,565 INFO  [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem
            19:38:50,601 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 27) Operation ("enable") failed - address: ([
                ("subsystem" => "datasources"),
                ("data-source" => "ExampleDS")
            ]) - failure description: "JBAS014802: Cannot resolve expression 'expression \"${test.jdbc.driver}\"' -- java.lang.IllegalStateException: Failed to resolve expression: ${test.jdbc.driver}"
            19:38:50,608 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
            19:38:50,651 INFO  [org.jboss.as.naming] (MSC service thread 1-1) JBAS011802: Starting Naming Service
            19:38:50,696 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-1) JBAS015400: Bound mail session [java:jboss/mail/Default]
            19:38:50,715 INFO  [org.jboss.as.security] (MSC service thread 1-3) JBAS013100: Current PicketBox version=4.0.7.Final
            19:38:50,917 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-2) JBoss Web Services - Stack CXF Server 4.0.2.GA
            19:38:51,009 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-5) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080
            19:38:51,249 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-4) JBAS015012: Started FileSystemDeploymentService for directory C:\work\thirdparty\jboss-as-7.1.1.Final\standalone\deployments
            19:38:51,270 INFO  [org.jboss.as.remoting] (MSC service thread 1-4) JBAS017100: Listening on /127.0.0.1:9999
            19:38:51,271 INFO  [org.jboss.as.remoting] (MSC service thread 1-7) JBAS017100: Listening on /127.0.0.1:4447
            19:38:51,377 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
            19:38:51,378 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 2130ms - Started 130 of 205 services (74 services are passive or on-demand)
            

             

             

            And the results starting with the right system properties:

             

             

            $ ./bin/standalone.sh -c standalone.xml -Dtest.jdbc.driver=h2
            ...
            19:39:38,218 INFO  [org.jboss.modules] JBoss Modules version 1.1.1.GA
            19:39:38,345 INFO  [org.jboss.msc] JBoss MSC version 1.0.2.GA
            19:39:38,378 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting
            19:39:39,093 INFO  [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
            19:39:39,099 INFO  [org.xnio] XNIO Version 3.0.3.GA
            19:39:39,121 INFO  [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
            19:39:39,128 INFO  [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
            19:39:39,188 INFO  [org.jboss.as.naming] JBAS011800: Activating Naming Subsystem
            19:39:39,181 INFO  [org.jboss.as.connector.subsystems.datasources] JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
            19:39:39,168 INFO  [org.jboss.as.configadmin] JBAS016200: Activating ConfigAdmin Subsystem
            19:39:39,164 INFO  [org.jboss.as.security] JBAS013101: Activating Security Subsystem
            19:39:39,137 INFO  [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
            19:39:39,242 INFO  [org.jboss.as.naming] (MSC service thread 1-8) JBAS011802: Starting Naming Service
            19:39:39,257 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.
            19:39:39,275 INFO  [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem
            19:39:39,276 INFO  [org.jboss.as.security] (MSC service thread 1-4) JBAS013100: Current PicketBox version=4.0.7.Final
            19:39:39,289 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
            19:39:39,315 INFO  [org.jboss.as.connector] (MSC service thread 1-2) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
            19:39:39,457 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-2) JBAS015400: Bound mail session [java:jboss/mail/Default]
            19:39:39,628 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-7) JBoss Web Services - Stack CXF Server 4.0.2.GA
            19:39:39,737 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-3) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080
            19:39:39,792 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-8) JBAS015012: Started FileSystemDeploymentService for directory C:\work\thirdparty\jboss-as-7.1.1.Final\standalone\deployments
            19:39:39,796 INFO  [org.jboss.as.remoting] (MSC service thread 1-2) JBAS017100: Listening on /127.0.0.1:4447
            19:39:39,797 INFO  [org.jboss.as.remoting] (MSC service thread 1-7) JBAS017100: Listening on /127.0.0.1:9999
            19:39:40,092 INFO  [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
            JBAS014775:    New missing/unsatisfied dependencies:
                  service jboss.jdbc-driver.${test_jdbc_driver} (missing) dependents: [service jboss.data-source.java:jboss/datasources/ExampleDS]
            
            
            19:39:40,147 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
            19:39:40,147 ERROR [org.jboss.as] (Controller Boot Thread) JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors) in 2101ms - Started 131 of 208 services (2 services failed or missing dependencies, 74 services are passive or on-demand)