我正在使用Spring路由数据源,如此处所述,并且运行良好。现在,我想添加连接池(Apache DBCP)。我将基本数据源更改为连接池数据源。好吧,它不起作用。
在服务器启动时,我看到连接池正在发生,我可以调试Apache的代码,但是当我尝试通过我的代码访问数据库时,我转到路由数据源,然后从那里到用于获取连接的DriverManager类 - 完全忽略Apache的代码。
<bean id="catalogDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClass}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.user}" />
<property name="password" value="${jdbc.pwd}" />
</bean>
<bean id="pool" class="org.apache.commons.pool.impl.GenericObjectPool">
<property name="minEvictableIdleTimeMillis"><value>300000</value></property>
<property name="timeBetweenEvictionRunsMillis"><value>60000</value></property>
</bean>
<bean id="dsConnectionFactory" class="org.apache.commons.dbcp.DataSourceConnectionFactory">
<constructor-arg><ref bean="catalogDataSource"/></constructor-arg>
</bean>
<bean id="poolableConnectionFactory" class="org.apache.commons.dbcp.PoolableConnectionFactory">
<constructor-arg index="0"><ref bean="dsConnectionFactory"/></constructor-arg>
<constructor-arg index="1"><ref bean="pool"/></constructor-arg>
<constructor-arg index="2"><null/></constructor-arg>
<constructor-arg index="3"><null/></constructor-arg>
<constructor-arg index="4"><value>false</value></constructor-arg>
<constructor-arg index="5"><value>true</value></constructor-arg>
</bean>
<bean id="pooledDS" class="org.apache.commons.dbcp.PoolingDataSource" depends-on="poolableConnectionFactory">
<constructor-arg><ref bean="pool"/></constructor-arg>
</bean>
<bean id="routingDataSource" class="something that derived from RoutingDataSource">
<property name="defaultTargetDataSource" ref="pooledDS"/>
<property name="targetDataSources">
<map key-type="java.lang.Integer">
</map>
</property>
</bean>
你能帮助我吗 - 我做错了什么?