<?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 配置多个数据源的文件的更多相关文章

  1. Spring配置多个数据源

    Spring 配置多数据源实现数据库读写分离 博客分类: Spring 数据库   现在大型的电子商务系统,在数据库层面大都采用读写分离技术,就是一个Master数据库,多个Slave数据库.Mast ...

  2. Spring配置扫描mybatis的mapper文件注意:

    一般会将不业务的mapper文件放到不同的包中: spring配置扫描就需要配置下面的方式(两个*): <!-- mybatis文件配置,扫描所有mapper文件 --> <bean ...

  3. Spring 配置多个数据源,并实现动态切换

    1.配置两个不同的数据源,如下 <!-- 数据源配置1 --> <bean id="testDataSource1" class="com.alibab ...

  4. SSH框架系列:Spring配置多个数据源

    分类: [java]2013-12-09 16:59 1247人阅读 评论(0) 收藏 举报 1.问题的引入 对于普通的SSH框架而言,一般配置一个数据源,一个SessionFactory,一个事务管 ...

  5. Spring配置,JDBC数据源及事务

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  6. Spring配置多个数据源,并实现数据源的动态切换转载)

    1.首先在config.properties文件中配置两个数据库连接的基本数据.这个省略了 2.在spring配置文件中配置这两个数据源: 数据源1 <!-- initialSize初始化时建立 ...

  7. 使用Spring配置数据源JdbcTemplate

    c3p0作为演示 1.编写资源文件(db.properties) jdbc.user=root jdbc.password=root jdbc.jdbcUrl=jdbc:mysql://localho ...

  8. Spring配置连接池

    ---------------------siwuxie095                                 Spring 配置连接池         1.Spring 配置内置连接 ...

  9. Spring配置数据源

    Spring在第三方依赖包中包含了两个数据源的实现类包,其一是Apache的DBCP,其二是 C3P0.可以在Spring配置文件中利用这两者中任何一个配置数据源. DBCP数据源 DBCP类包位于 ...

随机推荐

  1. javaWEB项目感受

    1.WEB-INF下的内容是受保护的,不能直接访问,可以通过转发的方式访问. 2.OGNL技术: 对象图像导航语言,是一种功能强大的表达式语言.可以让我们用非常简单的表达式访问对象层. OGNL引擎访 ...

  2. Leetcode-283 Move Zeroes

    #283.   Move Zeroes Given an array nums, write a function to move all 0's to the end of it while mai ...

  3. 爬虫神器xpath的用法(一)

    1.如果你没有安装lxml,请运行pip install lxml或者easy_install lxml安装,如果在安装过程中失败的话, 是因为lxml需要依赖某些库文件,具体可以问下度娘,这里不再赘 ...

  4. BeginInvoke与EndInvoke方法解决多线程接收委托返回值问题

    BeginInvoke与EndInvoke方法解决多线程接收委托返回值问题 原文:http://www.sufeinet.com/thread-3707-1-1.html      大家可以先看看我上 ...

  5. mysql 创建用户并赋予权限

    mysql> create user 'zhangsan'@'localhost' identified by '123456'; Query OK, 0 rows affected (0.00 ...

  6. [UWP]一种利用Behavior 将StateTrigger集中管理的方案

    不做开篇废话,我们发现: AdaptiveTrigger 不够好 我们知道,UWP可以在一个页面适应不同尺寸比例的屏幕.一般来说这个功能是通过官方推荐的AdaptiveTrigger 进行的. 比如这 ...

  7. How to apply Local Group Policy settings silently using the ImportRegPol.exe and Apply_LGPO_Delta.exe utilities.

    参考:http://supportishere.com/how-to-apply-local-group-policy-settings-silently-using-the-importregpol ...

  8. Android SDK下载和更新失败的解决方法【转】

    启动 Android SDK Manager ,打开主界面,依次选择「Tools」.「Options...」,弹出『Android SDK Manager - Settings』窗口:在『Androi ...

  9. HTML:模拟链接被按下,在新标签页打开页面,不使用window.open(可能被拦截)

    当按下一个按钮时,想打开一个新的标签页,可以使用window.open去实现但是因为使用window.open在新窗口或者新标签页中打开页面,有可能被浏览器给拦截.为了解决这个问题,可以模拟链接被按下 ...

  10. 每日英语:Mistrust Between U.S., Malaysia Strains Probe

    Mistrust between U.S. and Malaysian air-accident investigators has hampered a multinational probe in ...