3 Replies Latest reply on Aug 8, 2012 5:35 AM by prabhun

    DBCP connection pool in JBoss AS 7.1.1 standalone server

    prabhun

      Hi,

       

      I need to configure MySql with DBCP Connection pool in JBoss AS 7.1.1 standalone server.

       

      I deployed Mysql Driver jar - mysql-connector-java-5.1.15-bin.jar as a JBoss module (under modules/com/mysql/main) and added the following information in standalone.xml

       

       

      <drivers>

                          .........................

       

                        

                          <driver name="com.mysql" module="com.mysql">

                               <datasource-class>org.apache.commons.dbcp.BasicDataSource</datasource-class>

                          </driver>  

       

      </drivers>

       

       


       

      I tried the below approach,

       

      • Specified the datasource class "org.apache.commons.dbcp.BasicDataSource" for the tag <datasource-class> for the driver as shown above
      • Added datasource information to standalone.xml as below

       

       

       

      <datasource jta="false" jndi-name="java:jboss/datasources/MyDS" pool-name="MyDataSource" enabled="true" use-ccm="false">

              ......

       

                      <driver-class>com.mysql.jdbc.Driver</driver-class>

                          <driver>com.mysql</driver>

       

                     <pool>

                              <min-pool-size>2</min-pool-size>

                              <max-pool-size>20</max-pool-size>

                       </pool>

      ............

      </datasource>

       


       

      • And accessed the datasource JNDI in Spring application-context.xml as below

       

      <jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/MyDS"/>

       

       

       

       

      Got the below error on server startup

       

      Error creating bean with name 'dataSource': Post-processing of the FactoryBean's object failed;

       


       

      If we specify the DBCP datasource in application-context as below (as bean) this will work, however for any change we need to build and deploy.

       

      <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

              <property name="driverClassName" value="com.mysql.jdbc.Driver" />

              <property name="url" value="jdbc:mysql://localhost/testdb" />

              <property name="username" value="root" />

              <property name="password" value="root" />

              <property name="initialSize" value="5"/>

                <property name="defaultAutoCommit" value="false" />

               <property name="maxActive" value="10" />

                <property name="maxIdle" value="10" />

                <property name="maxWait" value="15000" />

      </bean>

       

       


       

      What is the prefered way to configure DBCP with MySQL in JBoss AS 7.1.1?

       

       

      Thanks,

      Prabhu

        • 1. Re: DBCP connection pool in JBoss AS 7.1.1 standalone server
          wdfink

          You might have a look into https://community.jboss.org/wiki/DataSourceConfigurationinAS7#Installing_a_JDBC_driver_as_a_module

           

          Also you can install the driver as module and start the JBoss (without a datasource). You will see that the driver is started successful.

          1 of 1 people found this helpful
          • 2. Re: DBCP connection pool in JBoss AS 7.1.1 standalone server
            prabhun

            Thanks Wolf-Dieter,

             

            I have gone through the link for Datasource configuration. I could load the mysql driver by specifying just the driver descriptor.

             

            <driver name="com.mysql" module="com.mysql">

            </driver>

             

            To link mysql and DBCP org.apache.commons.dbcp.BasicDataSource I specified the datasource descriptor like below,

             

            <datasource jta="false" jndi-name="java:jboss/datasources/MyDS" pool-name="MyDataSource" enabled="true" use-ccm="false">

                                <connection-url>jdbc:mysql://localhost/testdb</connection-url>

                                <driver-class>com.mysql.jdbc.Driver</driver-class>

                                <datasource-class>org.apache.commons.dbcp.BasicDataSource</datasource-class>

                                <driver>custom.mysql</driver>

                                <pool>

                                    <min-pool-size>2</min-pool-size>

                                    <max-pool-size>20</max-pool-size>

                                </pool>

                                <security>

                                    <user-name>root</user-name>

                                    <password>root</password>

                                </security>

                                <validation>

                                    <validate-on-match>false</validate-on-match>

                                    <background-validation>false</background-validation>

                                </validation>

                                <statement>

                                    <share-prepared-statements>false</share-prepared-statements>

                                </statement>

                            </datasource>

             

             

            When I look up through JNDI I get reference to org.jboss.jca.adapters.jdbc.WrapperDataSource

             

            Do I need to change anything to get reference to dbcp.BasicDataSource?

             


            Regards,

            Prabhu

            • 3. Re: DBCP connection pool in JBoss AS 7.1.1 standalone server
              prabhun

              I understood that JBoss is wrapping the underlying DBCP DataSource.

               

              I am using like,

               

              dataSource = (DataSource) initCtx.lookup("java:jboss/datasources/MyDS");

               

              I think now I can play around with the connection pooling settings by changing in standalone xml.