Question: How does the jdbc-pool plugin replace Commons DBCP?
jdbc-pool plugin uses a clever trick to replace Commons DBCP:
def doWithSpring = {
springConfig.beanNames.each { beanName ->
if(beanName.startsWith('dataSource')) {
def beanconf=springConfig.getBeanConfig(beanName)
if(beanconf.beanDefinition.beanClassName=='org.apache.commons.dbcp.BasicDataSource') {
beanconf.beanDefinition.beanClassName='org.apache.tomcat.jdbc.pool.DataSource'
}
}
} }(http://svn.codehaus.org/grails-plugins/grails-jdbc-pool/trunk/JdbcPoolGrailsPlugin.groovy)
Question: Do I have to download Tomcat JDBC Pool jars manually?
No, The latest version of jdbc-pool plugin defines a dependency :
dependencies {
runtime 'org.apache.tomcat:com.springsource.org.apache.tomcat.jdbc:1.0.8.5'
}(gets it from SpringSource's EBR repository, using ebr() in repositories closure: http://svn.codehaus.org/grails-plugins/grails-jdbc-pool/trunk/grails-app/conf/BuildConfig.groovy)
Question: How can I enable a JMX MBean for Tomcat JDBC Pool?
I've enabled the JMX MBean for Tomcat JDBC Pool by adding these beans to resources.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="grailsApplicationName" class="java.lang.String">
<constructor-arg><value>#{T(grails.util.Metadata).getCurrent().applicationName}</value></constructor-arg>
</bean> <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true"/>
</bean> <bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="JDBC:type=pool,application=#{grailsApplicationName}">
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="dataSourceUnproxied"/>
<property name="targetMethod" value="getPool"/>
</bean>
</property>
<property name="targetMethod" value="getJmxPool"/>
</bean>
</entry>
</map>
</property>
<property name="server" ref="mbeanServer"/>
</bean>
</beans>