<?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:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 框架 -->
<bean id="messageFactory" class="catf.core.message.factory.MessageFactory">
<constructor-arg index="0" name="resource" value="catf/resource/mapper/msg/catf_messages_mapper.xml"/>
</bean> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:spring/handler.properties</value>
<value>classpath*:/config/扩展api/expand-base-config.properties</value>
<value>classpath:spring/ffmpeg.properties</value>
<value>classpath:公共数据/mysql配置.properties</value>
</list>
</property>
<property name="fileEncoding" value="utf-8" />
</bean> <bean id="dataSourceParent" abstract="true" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="filters" value="stat" />
<property name="maxActive" value="20" />
<property name="initialSize" value="1" />
<property name="maxWait" value="60000" />
<property name="minIdle" value="1" />
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="poolPreparedStatements" value="true" />
<property name="maxOpenPreparedStatements" value="20" />
<property name="asyncInit" value="true" />
</bean> <bean id="dataSourceMaserati" parent="dataSourceParent">
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean> <bean id="dataSourceBentley" parent="dataSourceParent">
<property name="url" value="${jdbc2.url}" />
<property name="username" value="${jdbc2.username}" />
<property name="password" value="${jdbc2.password}" />
</bean> <bean id="dataSourceSwitcher" class="catf.component.mybatis.manager.ThreadLocalRountingDataSource">
<property name="targetDataSources">
<map>
<entry key="dataSourceMarserati" value-ref="dataSourceMaserati"/>
<entry key="dataSourceBentley" value-ref="dataSourceBentley"/>
</map>
</property>
<property name="defaultTargetDataSource" ref="dataSourceMaserati"/>
</bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceSwitcher"/>
<property name="typeAliasesPackage" value="catf.component.mybatis"/>
<property name="mapperLocations" value="classpath:catf/component/mybatis/mapper/mybatisMapper.xml"/>
</bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage="catf.component.mybatis.dao"
p:sqlSessionFactoryBeanName="sqlSessionFactory">
</bean> <!-- 4. 事务管理 : DataSourceTransactionManager -->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourceSwitcher"/>
</bean> <!-- 5. 使用声明式事务 -->
<tx:annotation-driven transaction-manager="txManager" /> <bean id="handlerStart" class="catf.core.handler.frame.spring.HandlerStart">
<property name="frameMessageHandler" value="${handler.message.frame}"/>
<property name="tstExecMessageHandler" value="${handler.message.tst.exec}"/>
<property name="interpreterHandler" value="${handler.interpreter}"/>
<property name="loaderHandler" value="${handler.loader}"/>
<property name="fileOperateHandler" value="${handler.file.operate}"/>
</bean>
<bean id="ffmpegConfig" class="catf.executor.record.model.FFmpegConfig">
<property name="windowsCmd" value="${ffmpeg.win}"/>
<property name="linuxCmd" value="${ffmpeg.lx}"/>
<property name="macOSCmd" value="${ffmpeg.mac}"/>
</bean> <context:component-scan
base-package="catf.core.thread.pool,catf.core.handler.frame.spring,catf.core.message.service,catf.core.xml.service">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:exclude-filter type="regex" expression="catf.core.handler.frame.spring.HandlerStart"/>
</context:component-scan>
<context:component-scan
base-package="catf.interpreter, catf.loader, catf.executor">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:exclude-filter type="regex" expression="catf.executor.record.model.FFmpegConfig"/>
</context:component-scan> <!-- component -->
<context:component-scan
base-package="catf.component">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:exclude-filter type="regex" expression="catf.executor.record.model.FFmpegConfig"/>
</context:component-scan>
<aop:aspectj-autoproxy proxy-target-class="true" /> <!-- 扩展组件 -->
<context:component-scan
base-package="catf.expand.component.base">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
<context:component-scan
base-package="catf.expand">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
<context:component-scan
base-package="catf.expand.component.web">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
<context:component-scan
base-package="weshare.token">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan> </beans>

mysql配置.properties

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://20.1.1.11:16306/maserati?tinyInt1isBit=false&autoReconnect=true
jdbc.username=root
jdbc.password=root jdbc2.driver=com.mysql.cj.jdbc.Driver
jdbc2.url=jdbc:mysql://20.1.1.11:16306/bentley?tinyInt1isBit=false&autoReconnect=true
jdbc2.username=root
jdbc2.password=root
ThreadLocalRountingDataSource.class
 package catf.component.mybatis.manager;

 import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

 public class ThreadLocalRountingDataSource extends AbstractRoutingDataSource {
@Override
protected Object determineCurrentLookupKey() {
return DataSourcesTypeManager.get();
} }
DataSourcesTypeManager .class
 package catf.component.mybatis.manager;

 public class DataSourcesTypeManager {

     private static final ThreadLocal<String> dataSourceTypes = new ThreadLocal<>();

     public static String get() {
return dataSourceTypes.get();
} /**
* 设置数据源
*/
public static void set(String dataSourceType) {
dataSourceTypes.set(dataSourceType);
} /**
* 清除dataSourceKey的值
*/
public static void remove() {
dataSourceTypes.remove();
} }

Spring Mybatis多数据源配置范例的更多相关文章

  1. Spring+MyBatis多数据源配置实现

    最近用到了MyBatis配置多数据源,原以为简单配置下就行了,实际操作后发现还是要费些事的,这里记录下,以作备忘 不多废话,直接上代码,后面会有简单的实现介绍 jdbc和log4j的配置 #定义输出格 ...

  2. spring mybatis 多数据源配置

    1.创建好数据库的配置文件 mysql.url=jdbc:mysql://***/***?useUnicode=true&characterEncoding=UTF-8 mysql.usern ...

  3. springMVC+spring+mybatis多数据源配置

    1.application.properties配置 <?xml version="1.0" encoding="UTF-8"?> <bean ...

  4. Spring+Mybatis多数据源配置

    一.配置文件 properties ds1.driverClassName=com.mysql.jdbc.Driver ds1.url=jdbc:mysql://192.168.200.130:330 ...

  5. Spring实现多数据源配置

    一.前言 对于小型项目,服务器与数据库是可以在同一台机子上的,但随着业务的庞大与负责,数据库和服务器就会分离开来.同时随着数据量的增大,数据库也要分开部署到多台机子上. 二.Spring配置文件修改 ...

  6. Spring Boot 2.X(五):MyBatis 多数据源配置

    前言 MyBatis 多数据源配置,最近在项目建设中,需要在原有系统上扩展一个新的业务模块,特意将数据库分库,以便减少复杂度.本文直接以简单的代码示例,如何对 MyBatis 多数据源配置. 准备 创 ...

  7. MyBatis多数据源配置(读写分离)

    原文:http://blog.csdn.net/isea533/article/details/46815385 MyBatis多数据源配置(读写分离) 首先说明,本文的配置使用的最直接的方式,实际用 ...

  8. spring,mybatis事务管理配置与@Transactional注解使用[转]

    spring,mybatis事务管理配置与@Transactional注解使用[转] spring,mybatis事务管理配置与@Transactional注解使用 概述事务管理对于企业应用来说是至关 ...

  9. spring,mybatis事务管理配置与@Transactional注解使用

    spring,mybatis事务管理配置与@Transactional注解使用[转]   spring,mybatis事务管理配置与@Transactional注解使用 概述事务管理对于企业应用来说是 ...

随机推荐

  1. JAVA 探究NIO

    事情的开始 1.4版本开始,java提供了另一套IO系统,称为NIO,(New I/O的意思),NIO支持面向缓冲区的.基于通道的IO操作. 1.7版本的时候,java对NIO系统进行了极大的扩展,增 ...

  2. RDIFramework.NET V3.3 Web版新增系统公告、系统新闻模块方便需要的客户

    1.系统新闻功能描述 在RDIFramework.NET V3.3版本中新增了系统新闻模块,用户可以根据实际情况做相应应用,如用在内部业务系统的展示中或网站上新闻的展示.新闻可以分类进行管理,非常的实 ...

  3. 2.1命令行和JSON的配置「深入浅出ASP.NET Core系列」

    希望给你3-5分钟的碎片化学习,可能是坐地铁.等公交,积少成多,水滴石穿,谢谢关注. 命令行配置 1.新建控制台项目 2.nuget引入microsoft.aspnetcore.all 这里要注意版本 ...

  4. Java服务器内存过高&CPU过高问题排查

    一.内存过高 1.内存过高一般有两种情况:内存溢出和内存泄漏 (1)内存溢出:程序分配的内存超出物理机的内存大小,导致无法继续分配内存,出现OOM报错 (2)内存泄漏:不再使用的对象一直占据着内存不释 ...

  5. HTTP协议及其相关

    URI.URL.URN URL,统一资源定位符,用来标识某一处资源的地址,必须包含协议和域名,协议指的是HTTP.FTP.WS.file等协议,域名就是常说的网址,比如www.baidu.com ,其 ...

  6. InnoSetup 脚本打包及管理员权限设置

    InnoSetup使用教程:InnoSetup打包安装 脚本详细 1. 定义变量 #define MyAppName "TranslationTool" #define MyApp ...

  7. MyBatis缓存策略

    MyBatis 提供了一级缓存和二级缓存策略,一级缓存是作用在SqlSession级别上的,而二级缓存则是作用在Mapper级别上的( 即作用在 namespace上),MyBatis 默认是开启的一 ...

  8. Java多线程知识整理

    多线程 1. 多线程基础 多线程状态转换图 普通方法介绍 yeild yeild,线程让步.是当前线程执行完后所有线程又统一回到同一起跑线.让自己或者其他线程运行,并不是单纯的让给其他线程. join ...

  9. springboot源码分析-SpringApplication

    SpringApplication SpringApplication类提供了一种方便的方法来引导从main()方法启动的Spring应用程序 SpringBoot 包扫描注解源码分析 @Spring ...

  10. 迭代器模式 Iterator 行为型 设计模式(二十)

    迭代器模式(Iterator)   走遍天下,世界那么大,我想去看看   在计算机中,Iterator意为迭代器,迭代有重复的含义,在程序中,更有“遍历”的含义 如果给定一个数组,我们可以通过for循 ...