采用spring将ibatis与proxool进行整合,利用spring将proxool数据源注入到sqlMapClient中去
一、web.xml配置Proxool
<!-- initial the datasource pool-->二、ProxoolConf.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/ProxoolConf.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>proxooladmin</servlet-name>
<servlet-class>
org.logicalcobwebs.proxool.admin.servlet.AdminServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>proxooladmin</servlet-name>
<url-pattern>/proxooladmin</url-pattern>
</servlet-mapping>
<?xml version="1.0" encoding="utf-8"?>三、applicationContext-resources.xml将Proxool数据源配置在spring中
<something-else-entirely>
<proxool>
<alias>sc</alias>
<!-- 公司测试 -->
<driver-url>jdbc:oracle:thin:@192.168.x.x:1521:ORCL</driver-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<driver-properties>
<property name="user" value=""/>
<property name="password" value=""/>
</driver-properties>
<house-keeping-sleep-time>30000</house-keeping-sleep-time>
<prototype-count>10</prototype-count>
<maximum-connection-count>300</maximum-connection-count>
<minimum-connection-count>5</minimum-connection-count>
<simultaneous-build-throttle>50</simultaneous-build-throttle>
<house-keeping-test-sql>select sysdate from dual</house-keeping-test-sql>
<maximum-active-time>300000</maximum-active-time>
<maximum-connection-lifetime>3600000</maximum-connection-lifetime>
<test-before-use>true</test-before-use>
<test-after-use>true</test-after-use>
<verbose>true</verbose>
<trace>true</trace>
</proxool>
<!-- 连接 呼叫平台系统-->
<proxool>
<alias>callCenter</alias>
<driver-url>jdbc:jtds:sqlserver://192.168.x.x:1433/scsis</driver-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value=""/>
<property name="password" value=""/>
</driver-properties>
<house-keeping-sleep-time>30000</house-keeping-sleep-time>
<prototype-count>10</prototype-count>
<maximum-connection-count>5</maximum-connection-count>
<minimum-connection-count>1</minimum-connection-count>
<simultaneous-build-throttle>10</simultaneous-build-throttle>
<house-keeping-test-sql>select getdate()
</house-keeping-test-sql>
<maximum-active-time>300000</maximum-active-time>
<maximum-connection-lifetime>3600000</maximum-connection-lifetime>
<test-before-use>true</test-before-use>
<test-after-use>true</test-after-use>
<verbose>true</verbose>
<trace>true</trace>
</proxool>
</something-else-entirely>
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd"><bean id="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName"><value>org.logicalcobwebs.proxool.ProxoolDriver</value></property><property name="url"><value>proxool.sc</value></property></bean><!-- 呼叫中心 --><bean id="callCenterDataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName"><value>org.logicalcobwebs.proxool.ProxoolDriver</value></property><property name="url"><value>proxool.callCenter</value></property></bean></beans>四、applicationContext-ibatis.xml配置将Proxool数据源注入到Ibatis的sqlMapClient中。指定每个数据源分配对应的*-sql-map-config.xml文件,并为Ibatis的dao层实现类指定相应的数据源
<?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-2.0.xsd">
<!-- SqlMap setup for iBATIS Database Layer -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:/com/sasis/dao/ibatis/sqlMap/sql-map-config.xml
</value>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<!-- UserDao: iBatis implementation -->
<bean id="userDao" class="com.sasis.dao.ibatis.UserDaoiBatis">
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
<!--呼叫平台系统-->
<bean id="callCenterSqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:/com/sasis/dao/ibatis/sqlMap/genGoldVip-sql-map-config.xml
</value>
</property>
<property name="dataSource" ref="callCenterDataSource" />
</bean>
<bean id="genGoldVipDao" class="com.sasis.dao.ibatis.GenGoldVipDaoImpl">
<property name="sqlMapClient" ref="callCenterSqlMapClient" />
</bean>
</beans>