spring+ibatis+多数据源
环境:spring3.1+ibatis2.3.4+oracle+hbase
要求:需要在工程中操作两个不同的数据源,一个是mssql,另一个是hbase。
实现:
<bean id="hbaseDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.apache.phoenix.jdbc.PhoenixDriver"/>
<property name="url" value="jdbc:phoenix:IP"/>
</bean>
<!-- 数据库连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url"
value="jdbc:sqlserver://xxx.xxx.xxx.xxx:1433;DatabaseName=xxx" />
<property name="username" value="sa" />
<property name="password" value="xxxxxxx" />
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="sql-map-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="sqlMapClientForHBase" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="sql-map-config-hbase.xml" />
<property name="dataSource" ref="hbaseDataSource" />
</bean>
<bean id="baseService" class="xxx.xxx.serviceimpl.base.BaseServiceImpl">
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
<bean id="baseServiceForHBase" class="xxx.xxx.serviceimpl.base.BaseServiceImpl">
<property name="sqlMapClient" ref="sqlMapClientForHBase" />
</bean>
本文来自博客园,作者:huiy_小溪,转载请注明原文链接:https://www.cnblogs.com/huiy/p/5391271.html