spring+ibatis多数据源

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>WEB-INF/config/jdbc.properties </value>
</list>
</property>
</bean>

<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- 数据源的加载 -->


<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation"
value="/WEB-INF/config/sqlMap-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>

DAO层是:
public class DepartmentDaoImp extends SqlMapClientDaoSupport implements
DepartmentDao {

public int addDepartment(DepartmentInfo departmentInfo) {

return getSqlMapClientTemplate().update("Department.addDepartment", departmentInfo);
}

 

 

当然可以配置多个,sqlMapClient只是默认的,你可以自己配置多个呀
<bean id="userDaoImp" class="gov.ynfda.dao.UserDaoImp">
<property name="sqlMapClient" ref="sqlMapClient" />
<property name="sqlMapClient1" ref="sqlMapClient" />
<property name="sqlMapClient2" ref="sqlMapClient2" />
<property name="sqlMapClient3" ref="sqlMapClient3" />
</bean>

transactionManager也分成多个
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="transactionManager1"......
<bean id="transactionManager2"......

然后再你的dao类里面声明(sqlMapClient是默认的无需声明)
private SqlMapClient sqlMapClient1;
private SqlMapClient sqlMapClient2;
private SqlMapClient sqlMapClient3;

get/set ......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值