项目中使用SSI框架进行网站开发, 在网上看到很多人关注ibatis多数据库连接。我把我们项目的解决方案写出来供大家参考。
1.在Config文件夹中配置多个数据库配置文件。
jdbc.properties
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver jdbc.url=jdbc:oracle:thin:@192.168.24.136:1521:jdbc jdbc.username=xxxx jdbc.password=xxxxhq.properties
hq.driverClassName=oracle.jdbc.driver.OracleDriver hq.url=jdbc:oracle:thin:@192.168.24.136:1521:hq hq.username=xxx hq.password=xxx
<!-- 属性文件读入--> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath*:config/hq.properties</value> <value>classpath*:config/jdbc.properties</value> <value>classpath*:config/jdbcFilter.properties</value> <value>classpath*:config/webcall.properties</value> </list> </property> </bean >dataAccessContext-ibatis.xml
<bean id="dataSourceHQ" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${hq.driverClassName}"/> <property name="jdbcUrl" value="${hq.url}"/> <property name="user" value="${hq.username}"/> <property name="password" value="${hq.password}"/> <property name="minPoolSize" value="2"/> <property name="maxPoolSize" value="10"/> </bean> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${jdbc.driverClassName}"/> <property name="jdbcUrl" value="${jdbc.url}"/> <property name="user" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="minPoolSize" value="2"/> <property name="maxPoolSize" value="10"/> <property name="preferredTestQuery" value="select 1 from dual"/> <property name="testConnectionOnCheckin" value="true"/> </bean>
<bean id="sqlMapClientTTDate" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation"> <value>classpath:/config/sqlConfigHQ.xml</value> </property> <property name="dataSource" ref="dataSourceHQ" /> <property name="lobHandler"> <ref local="oracleLobHandler" /> </property> </bean>
<bean id="sqlMapClient" class="com.cssweb.common.dao.ibatis.SqlMapClientFactoryBean"> <property name="configLocation"> <value>classpath:/config/SqlMapConfig.xml</value> </property> <property name="mappingLocations"> <list> <value>classpath*:/com/cssweb/**/pojo/*.sqlMap.xml</value> </list> </property> <property name="dataSource" ref="dataSource"/> <property name="lobHandler" ref="oracleLobHandler"/> <property name="sqlExecutor"> <bean class="com.cssweb.common.dao.ibatis.LimitSqlExecutor"> <property name="dialect"><bean class="com.cssweb.common.dao.dialect.OracleDialect"/></property> </bean> </property> </bean>