spring 配置多个数据源的文件
<?xml version="1.0" encoding="UTF-8"?>
<!-- Repository and Service layers -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd">
<!-- ========================= Repository RESOURCE DEFINITIONS ========================= -->
<bean id="slave" class="org.apache.tomcat.jdbc.pool.DataSource">
<property name="driverClassName" value="${jdbc.mysql.Driver}"/>
<property name="url" value="${slave.connection}"/>
<property name="username" value="${slave.username}"/>
<property name="password" value="${slave.password}"/>
<!--公共配置属性 -->
<property name="maxActive" value="100"/>
<property name="initialSize" value="10"/>
<property name="minIdle" value="10"/>
<property name="jdbcInterceptors" value="${tomcat.jdbc.pool.jdbcInterceptors}"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="true"/>
<property name="validationQuery" value="select 1"/>
<property name="testOnReturn" value="false"/>
<property name="validationInterval" value="30000"/>
<property name="timeBetweenEvictionRunsMillis" value="5000"/>
<property name="maxWait" value="15000"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="60"/>
<property name="logAbandoned" value="false"/>
<property name="minEvictableIdleTimeMillis" value="30"/>
</bean>
<bean id="master" class="org.apache.tomcat.jdbc.pool.DataSource">
<property name="driverClassName" value="${jdbc.mysql.Driver}"/>
<property name="url" value="${master.connection}"/>
<property name="username" value="${master.username}"/>
<property name="password" value="${master.password}"/>
<!--公共配置属性 -->
<property name="maxActive" value="100"/>
<property name="initialSize" value="10"/>
<property name="minIdle" value="10"/>
<property name="jdbcInterceptors" value="${tomcat.jdbc.pool.jdbcInterceptors}"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="true"/>
<property name="validationQuery" value="select 1"/>
<property name="testOnReturn" value="false"/>
<property name="validationInterval" value="30000"/>
<property name="timeBetweenEvictionRunsMillis" value="5000"/>
<property name="maxWait" value="15000"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="60"/>
<property name="logAbandoned" value="false"/>
<property name="minEvictableIdleTimeMillis" value="30"/>
</bean>
<bean id="oldmemberdb" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="${oldmemberdb.connection}"/>
<property name="username" value="${oldmemberdb.username}" />
<property name="password" value="${oldmemberdb.password}" />
</bean>
<bean id="dataSource" class="db.DynamicDataSource">
<property name="master" ref="master"/>
<property name="slaves">
<list>
<ref bean="slave"/>
</list>
</property>
</bean>
<!-- ibatis3 工厂类 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:sqlMapConfig.xml"/>
<property name="mapperLocations"
value="classpath:/jdbc/uc/dao/*.xml"/>
<property name="typeAliasesPackage" value="uc.jdbc.uc.po"/>
</bean>
<bean id="sqlSessionFactory_1" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="oldmemberdb"/>
<property name="configLocation" value="classpath:sqlMapConfig.xml"/>
<property name="mapperLocations"
value="classpath:/uc/jdbc/uc/dao/TestMapper.xml"/>
<property name="typeAliasesPackage" value="uc.jdbc.uc.po"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="uc.jdbc.uc.olddao"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory_1"></property>
</bean>
<bean class="MapperScannerConfigurer">
<property name="basePackage" value="uc.jdbc.uc.dao"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<!-- 定义单个jdbc数据源的事务管理器 -->
<bean id="transactionManager"
class="DynamicDataSourceTransactionManager">
<!-- class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> -->
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 以 @Transactional 标注来定义事务 -->
<tx:annotation-driven transaction-manager="trasactionManager"
proxy-target-class="true"/>
<bean id="transactionTemplate"
class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager"/>
<!--ISOLATION_DEFAULT 表示由使用的数据库决定 -->
<property name="isolationLevelName" value="ISOLATION_DEFAULT"/>
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
<property name="timeout" value="300"/>
</bean>
<bean id="transactionTemplateNew"
class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager"/>
<!--ISOLATION_DEFAULT 表示由使用的数据库决定 -->
<property name="isolationLevelName" value="ISOLATION_DEFAULT"/>
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"/>
<property name="timeout" value="300"/>
</bean>
</beans>
spring 配置多个数据源的文件的更多相关文章
- Spring配置多个数据源
Spring 配置多数据源实现数据库读写分离 博客分类: Spring 数据库 现在大型的电子商务系统,在数据库层面大都采用读写分离技术,就是一个Master数据库,多个Slave数据库.Mast ...
- Spring配置扫描mybatis的mapper文件注意:
一般会将不业务的mapper文件放到不同的包中: spring配置扫描就需要配置下面的方式(两个*): <!-- mybatis文件配置,扫描所有mapper文件 --> <bean ...
- Spring 配置多个数据源,并实现动态切换
1.配置两个不同的数据源,如下 <!-- 数据源配置1 --> <bean id="testDataSource1" class="com.alibab ...
- SSH框架系列:Spring配置多个数据源
分类: [java]2013-12-09 16:59 1247人阅读 评论(0) 收藏 举报 1.问题的引入 对于普通的SSH框架而言,一般配置一个数据源,一个SessionFactory,一个事务管 ...
- Spring配置,JDBC数据源及事务
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- Spring配置多个数据源,并实现数据源的动态切换转载)
1.首先在config.properties文件中配置两个数据库连接的基本数据.这个省略了 2.在spring配置文件中配置这两个数据源: 数据源1 <!-- initialSize初始化时建立 ...
- 使用Spring配置数据源JdbcTemplate
c3p0作为演示 1.编写资源文件(db.properties) jdbc.user=root jdbc.password=root jdbc.jdbcUrl=jdbc:mysql://localho ...
- Spring配置连接池
---------------------siwuxie095 Spring 配置连接池 1.Spring 配置内置连接 ...
- Spring配置数据源
Spring在第三方依赖包中包含了两个数据源的实现类包,其一是Apache的DBCP,其二是 C3P0.可以在Spring配置文件中利用这两者中任何一个配置数据源. DBCP数据源 DBCP类包位于 ...
随机推荐
- kindle 贴膜
我自己贴膜也贴得很好.顺便和大家分享一下我的贴膜经验.需要的道具,一.抹布,二.一张银行卡,三.一卷小筒的透明胶.贴膜关键点,一.环境和贴面必须干净,二.用力要轻,三.顺序是从上往下.具体步骤:1.先 ...
- db2 表授权语句
grant insert/update/delete on table schema.table_name to user user_name;
- BZOJ 4300: 绝世好题 动态规划
4300: 绝世好题 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4300 Description 给定一个长度为n的数列ai,求ai的 ...
- nodejs express 框架解密1-总体结构
本文是基于express3.4.6的. 1.express 代码结构为: bin/express 是在命令行下的生成express 框架目录文件用的 lib/express 是框架的入口文件 lib/ ...
- 每日英语:A Different Color: China's Chameleonic Politics
China has tried your form of government and found it wanting. That was the message delivered by Chin ...
- Java Inner Classes
When thinking about inner classes in java, the first thing that comes to my mind is that, WHY do we ...
- No connection string named '***' could be found in the application config file
Code-First时更新数据库遇到妖孽问题“No connection string named '***' could be found in the application config fil ...
- chm格式文件能打开,但看不到内容问题
是chm格式的能打开文件,也能看到左边的目录信息,但是无法显示右面的具体内容.报错:无法显示网页.错误页面的url是:res://C:WINDOWSsystem32shdoclc.dll/dnserr ...
- IT战略规划咨询
目录 1IT战略规划微咨询简介 2IT战略的意义 3服务模式 4IT战略规划焦点问题 5IT战略规划步骤 6服务提供方微咨询网 7微咨询价值 8微咨询服务方式 9IT工作规划与IT战略规... IT战 ...
- 自己开发的csdn手机客户端
本人开发的,同步csdn官网新闻和博客内容,支持本地浏览,而且还可以手机上看到博客中的代码! 这是一款同步更新官网最新的资讯信息应用软件. 全新的用户界面,更好的用户体验,数据加载速度得到了进一步优化 ...