博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring多数据源配置
阅读量:4589 次
发布时间:2019-06-09

本文共 2143 字,大约阅读时间需要 7 分钟。

转:

 

多数据源问题,目的,可以使用xml来自由配置切换的数据源

 

spring-mybatis.xml

 

1 
2
15 16
17 18
20
21
22
classpath:jdbc.properties
23
classpath:config.properties
24
25
26 27 28
29
31
32
33
34
35
36
37
38
39
40
41 42
43
45
46
47
48
49
50
51
52
53
54
55 56
57
58
59
60
61
62
63
64
65 66
67
68
69
70
71
72
73
74 75
76
77
78 79
81
82
83

 

2. DynamicDataSource.class

package com.xxx.aop;import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;public class DynamicDataSource extends AbstractRoutingDataSource{	@Override	protected Object determineCurrentLookupKey() {		return DatabaseContextHolder.getCustomerType(); 	}}

 

3. DatabaseContextHolder.class

package com.xxx.aop;public class DatabaseContextHolder {	private static final ThreadLocal
contextHolder = new ThreadLocal
(); public static void setCustomerType(String customerType) { contextHolder.set(customerType); } public static String getCustomerType() { return contextHolder.get(); } public static void clearCustomerType() { contextHolder.remove(); }}

  

 

转载于:https://www.cnblogs.com/fengzhentian/p/4601886.html

你可能感兴趣的文章
打印图片,自动调整宽高
查看>>
对类使用dir()
查看>>
【13】淘宝sdk——入门实战之header.php制作(一)
查看>>
安装SoapUI Pro
查看>>
杜教BM模板
查看>>
Makefile经典教程(掌握这些足够)
查看>>
自己成功的编写的将数据从excel导入到access中
查看>>
【Leetcode】【Easy】Compare Version Numbers
查看>>
014 链表中倒数第k个结点
查看>>
Python的pip安装Django
查看>>
第一冲刺阶段——站立会议第二天4月19日
查看>>
hdu-----(2807)The Shortest Path(矩阵+Floyd)
查看>>
简洁的MysqlHelper
查看>>
Android面试收集录2 Broadcast Receiver详解
查看>>
基于HTML5实现的中国象棋游戏
查看>>
Luogu P2024 [NOI2001]食物链 | 并查集
查看>>
openLayers3 中实现多个Overlay
查看>>
SQlServer2008 之 定时执行sql语句作业的制定
查看>>
函数式编程
查看>>
由浅入深之Jquery笔记(1)
查看>>