DBCP connection pool in JBoss AS 7.1.1 standalone server
prabhun Aug 3, 2012 3:59 AMHi,
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