spring mybatis 多数据源之间怎么切换
2个回答
展开全部
<!-- 注解式事务管理 --
<tx:annotation-driven transaction-manager="transactionManager" /
<!-- 自动扫描 mybatis mapper接口 --
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
<property name="basePackage" value="com.test.tt.mapper" /
<property name="sqlSessionFactory" ref="sqlSessionFactory"</property</bean<!-- 数据源2--
<!-- proxool连接池 --
<bean id="dataSource_d2" class="org.logicalcobwebs.proxool.ProxoolDataSource"
<property name="alias" value="${d2.alias}" /
<property name="driver" value="${driver}" /
<property name="driverUrl" value="${d2.driverUrl}" /
<property name="user" value="${d2.user}" /
<property name="password" value="${d2.password}" /
<property name="houseKeepingTestSql" value="${house-keeping-test-sql}" /
<property name="maximumConnectionCount" value="${maximum-connection-count}" /
<property name="minimumConnectionCount" value="${minimum-connection-count}" /
<property name="prototypeCount" value="${prototype-count}" /
<property name="simultaneousBuildThrottle" value="${simultaneous-build-throttle}" /
<property name="trace" value="${trace}" /</bean
<bean id="sqlSessionFactory_d2" class="org.mybatis.spring.SqlSessionFactoryBean"
<property name="dataSource" ref="dataSource_d2" /
<property name="configLocation" value="classpath:mybatis-d2-config.xml"</property</bean<bean id="transactionManager_d2"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
<property name="dataSource" ref="dataSource_d2" /</bean
<!-- 注解式事务管理 --
<tx:annotation-driven transaction-manager="transactionManager" /
<!-- 自动扫描 mybatis mapper接口 --
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
<property name="basePackage" value="com.test.tt.mapper" /
<property name="sqlSessionFactory" ref="sqlSessionFactory"</property</bean<!-- 数据源2--
<!-- proxool连接池 --
<bean id="dataSource_d2" class="org.logicalcobwebs.proxool.ProxoolDataSource"
<property name="alias" value="${d2.alias}" /
<property name="driver" value="${driver}" /
<property name="driverUrl" value="${d2.driverUrl}" /
<property name="user" value="${d2.user}" /
<property name="password" value="${d2.password}" /
<property name="houseKeepingTestSql" value="${house-keeping-test-sql}" /
<property name="maximumConnectionCount" value="${maximum-connection-count}" /
<property name="minimumConnectionCount" value="${minimum-connection-count}" /
<property name="prototypeCount" value="${prototype-count}" /
<property name="simultaneousBuildThrottle" value="${simultaneous-build-throttle}" /
<property name="trace" value="${trace}" /</bean
<bean id="sqlSessionFactory_d2" class="org.mybatis.spring.SqlSessionFactoryBean"
<property name="dataSource" ref="dataSource_d2" /
<property name="configLocation" value="classpath:mybatis-d2-config.xml"</property</bean<bean id="transactionManager_d2"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
<property name="dataSource" ref="dataSource_d2" /</bean
<!-- 注解式事务管理 --
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询