<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:init-config.properties</value>
</property>
</bean>
<!-- enable component scanning (beware that this does not enable mapper scanning!) -->
<context:component-scan base-package="org.test.mybatis" />
<!-- enable autowire -->
<context:annotation-config />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- 基本属性 url、user、password -->
<property name="driverClassName" value="${master.dataSource.driver}"></property>
<property name="url" value="${master.dataSource.url}" />
<property name="username" value="${master.dataSource.username}" />
<property name="password" value="${master.dataSource.password}" />
</bean>
<!-- define the SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="org.test.mybatis.domain" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<property name="basePackage" value="org.test.mybatis.mapper" />
</bean>
<!-- transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
<qualifier value="master" />
</bean>
<!-- 全注解方式 需加上@Transactional -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 事务控制的业务方法配 -->
<!--
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="page*" read-only="true" />
<tx:method name="list*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
-->
<!-- 事务控制拦截 -->
<!--
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* org.test..*.service..*Service.*(..))"
advice-ref="txAdvice" />
</aop:config>
-->
<!-- =================================================================== -->
<!-- 数据源2 -->
<bean id="dataSource2" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- 基本属性 url、user、password -->
<property name="driverClassName" value="${slaver.dataSource.driver}"></property>
<property name="url" value="${slaver.dataSource.url}" />
<property name="username" value="${slaver.dataSource.username}" />
<property name="password" value="${slaver.dataSource.password}" />
</bean>
<bean id="sqlSessionFactory2" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource2" />
<property name="typeAliasesPackage" value="org.test.mybatis.domain2" />
<!--<property name="configLocation" value="classpath:conf/mybatis-config.xml"></property>-->
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory2"/>
<property name="basePackage" value="org.test.mybatis.mapper2" />
</bean>
<bean id="transactionManager2"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource2" />
<qualifier value="slaver" />
</bean>
<!-- 全注解方式 -->
<tx:annotation-driven transaction-manager="transactionManager2" />
</beans>
分享到:
相关推荐
Spring多数据源配置,支持mysql、oracle等多个数据源同时存在的情况
基于注解的Spring多数据源配置和使用 前一段时间研究了一下spring多数据源的配置和使用,为了后期从多个数据源拉取数据定时进行数据分析和报表统计做准备。由于之前做过的项目都是单数据源的,没有遇到这种场景,...
Spring多数据源配置_分布式数据 Tomcat服务器下的多数据源配置详情 一、环境及框架 Tomcat+spring+hibernate+jotm,还有就是struts、Oracle等 二、需求说明 系统里有2套不同网域的oracle数据库,之间的数据需要进行...
spring数据源配置
spring 动态多数据源配置代码,本项目是maven项目,里面有完成的配资好的spring多数据源代码和配置文件。
springboot多数据源配置
通过注解实现数据源的灵活切换
一个springboot的多数据配置,从mapper到controller完整的一个业务流程
主要介绍了spring多数据源配置实现方法,结合实例形式分析了spring多数据源配置相关操作技巧与使用注意事项,需要的朋友可以参考下
SSM(Spring+SpringMVC+MyBatis)多数据源配置框架,精简版
spring 配置多数据源
Spring Boot+Jpa多数据源配置Demo,可同时支持多种数据库,不同数据库,同时支持不同数据库的JdbcTemplate
搭建好eclipse版的ssm+maven+tk.mybatis+redis集成的demo。新手快速上手直接demo。完整高质量。整理不少时间分享没人赞好心疼吖吖。。。 或者直接看下面地址博客(由于太长所以博客不全) ...
阐述spring的数据源配置
项目中我们经常会遇到多数据源的问题,尤其是数据同步或定时任务等项目更是如此。本篇文章主要介绍了spring多数据源配置,有兴趣的可以了解一下。
通过简单的demo实现SpingBoot多数据源配置并动态切换多数据源
Spring Boot使用spring-data-jpa配置Mysql多数据源,可用版本
spring配置JNDI数据源
spring实现多数据源,可以在配置文件中添加