<?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. 学习ASP.NET Core Razor 编程系列十五——文件上传功能(三)

    学习ASP.NET Core Razor 编程系列目录 学习ASP.NET Core Razor 编程系列一 学习ASP.NET Core Razor 编程系列二——添加一个实体 学习ASP.NET ...

  2. git使用教程指南

    前言  Git是一个开源的分布式版本控制系统.其核心就在于版本控制.  在实际编码过程中,我们往往会忘记上次对文件的修改内容.若是刚刚修改的还好说,撤销操作即可.但若这是你昨天做的修改并关闭了IDE呢 ...

  3. SpringBoot整合系列--整合MyBatis-plus

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/10125279.html SpringBoot整合MyBatis-plus 步骤 第一步: ...

  4. Ubuntu16.04安装Qt5.12.2

    第一步:下载文件 https://download.qt.io/official_releases/qt/5.12/5.12.2/ 第二步:安装依赖库 sudo apt-get install bui ...

  5. javascript原型与原型链,prototype、__proto__、constructor

    javascript通过构造函数(constructor)和原型链来(prototype chain)实现其他面向对象语言的类概念.ES6语法中引入了“类”(class)的概念,但只是一个语法糖,只是 ...

  6. [置顶]生鲜配送管理系统_升鲜宝V2.0 销售订单汇总_采购任务分配功能_操作说明

    做好生鲜供应链系统,要注意三个方面,1.分拣 2 采购  3 库存,市面上做的比较成熟的功能,还是分拣这一块(按客户分拣.按订单分拣.按商品分类分拣.按商品分拣.按线路分拣.客户自由组合分拣)[下篇文 ...

  7. 【Android】用Cubism 2制作自己的Live2D——官方App样例源码学习(2)!

    前言- 明确了项目目录的结构,但是结构什么的也太"抽象"了. 本篇开始上代码! 模型的绘制- 前几天的学习中,live2d的绘制有了一些了解了,在Android端使用OpenGL ...

  8. SQL Server含逗号分隔的数据匹配维表

    日常有时候导出数据需求时,数据列会遇到带有分隔符的ID,但又需要匹配维表(如下图所示)将ID变成名称. 这种情况可以采用“分隔-匹配-合并”的方法 具体代码为: -- 准备工作1:创建事实表数据 CR ...

  9. Jar 初步

    前言 jar 是 java 文件中一种文件格式,用于将 .java 文件编译的字节码文件打包成 jar. 给 Java 应用打包 1. 新建一个 java 源文件 package cn.szxy; p ...

  10. Java三大特性

    Java 三大特性,算是Java独特的表现,提到Java 的三大特性, 我们都会想到封装, 继承和多态 这是我们Java 最重要的特性. 封装(Encapsulation) : 封装:是指隐藏对象的属 ...