一个项目中需要使用两个数据库,Oracle 和Mysql,于是参考各个blog,实现此功能。写好后才发现,原来的事务失效了,我去...
spring-mybatis.xml 配置
classpath:spring/db.properties public class MultipleDataSource extends AbstractRoutingDataSource { private static final ThreadLocal dataSources = new InheritableThreadLocal (); public static void setDataSource(String dataSource) { dataSources.set(dataSource); } //清除数据源 public static void clearDataSource() { dataSources.remove(); } @Override protected Object determineCurrentLookupKey() { return dataSources.get(); } }
使用demo
@DataSource(name = DataSource.mySqlDataSource)
public class ContentServiceImpl implements IContentService {
@Autowired
private IContentDao contentDao;
@Override
public Content queryOne(String type) {
return contentDao.queryOne(type);
}
}
以上这篇解决spring mvc 多数据源切换,不支持事务控制的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持考高分网。



