proxool.xml
可以配置多个数据源。
<?xml version="1.0" encoding="UTF-8"?> <something-else-entirely> <proxool> <alias>asset</alias> <driver-url>jdbc:mysql://127.0.0.1:3306/jsxy?useUnicode=true&characterEncoding=UTF-8</driver-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <driver-properties> <property name="user" value="root"/> <property name="password" value="root"/> </driver-properties> <minimum-connection-count>2</minimum-connection-count> <prototype-count>2</prototype-count> <maximum-connection-count>50</maximum-connection-count> <house-keeping-sleep-time>60000</house-keeping-sleep-time> <simultaneous-build-throttle>10</simultaneous-build-throttle> <test-before-use>true</test-before-use> <house-keeping-test-sql>select now()</house-keeping-test-sql> <injectable-prepared-statement-interface>java.sql.PreparedStatement</injectable-prepared-statement-interface> </proxool> <proxool> <alias>jpaasset</alias> <driver-url>jdbc:mysql://127.0.0.1:3306/jsxy?useUnicode=true&characterEncoding=UTF-8</driver-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <driver-properties> <property name="user" value="root"/> <property name="password" value="root"/> </driver-properties> <minimum-connection-count>2</minimum-connection-count> <prototype-count>2</prototype-count> <maximum-connection-count>50</maximum-connection-count> <house-keeping-sleep-time>60000</house-keeping-sleep-time> <simultaneous-build-throttle>10</simultaneous-build-throttle> <test-before-use>true</test-before-use> <house-keeping-test-sql>select now()</house-keeping-test-sql> <injectable-prepared-statement-interface>java.sql.PreparedStatement</injectable-prepared-statement-interface> </proxool> </something-else-entirely>
web.xml
<!--加载配置文件--> <servlet> <servlet-name>proxoolServletConfigurator</servlet-name> <servlet-class> org.logicalcobwebs.proxool.configuration.ServletConfigurator </servlet-class> <init-param> <param-name>xmlFile</param-name> <param-value>WEB-INF/classes/jdbcproxool.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!--proxool监控--> <servlet> <servlet-name>Admin</servlet-name> <servlet-class> org.logicalcobwebs.proxool.admin.servlet.AdminServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>Admin</servlet-name> <url-pattern>/proxoolAdmin</url-pattern> </servlet-mapping>
这里org.logicalcobwebs.proxool.configuration.ServletConfigurator加载一定要早于org.springframework.web.context.ContextLoaderListener。
Spring-Dao.xml
spring中使用proxool作为spring jdbc template的数据源。
<!--spring jdbc template--> <!--datasource--> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.logicalcobwebs.proxool.ProxoolDriver"/> <property name="url" value="proxool.asset"/> </bean> <!--jdbcTemplate使用datasource--> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource"/> </bean> <!--事务--> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!--事务注解--> <tx:annotation-driven transaction-manager="txManager"/>