Comments (3)
我的没有xml
@bean
//@ConfigurationProperties(prefix = "mybatis")
public SqlSessionFactoryBean sqlSessionFactoryBean() {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
// Here to config mybatis
// sqlSessionFactoryBean.setTypeAliasesPackage("cn.com.hellowood.dynamicdatasource.mapper");
// sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("mappers/**Mapper.xml"));
// Here is very important, if don't config this, will can't switch datasource
// put all datasource into SqlSessionFactoryBean, then will autoconfig SqlSessionFactory
sqlSessionFactoryBean.setDataSource(dynamicDataSource());
return sqlSessionFactoryBean;
}
from springboot-dynamicdatasource.
Switch DataSource to [slave] in Method [List com.weiyin.streetlamp.menu.dao.MenuDao.listAll()]
2020-11-03 12:36:43.669 [http-nio-0.0.0.0-8001-exec-7] INFO c.w.s.dynamicdatasource.DynamicRoutingDataSource - Current DataSource is [slave]
2020-11-03 12:36:43.674 [http-nio-0.0.0.0-8001-exec-7] INFO c.w.s.dynamicdatasource.DynamicDataSourceAspect - Restore DataSource to [master] in Method [List com.weiyin.streetlamp.menu.dao.MenuDao.listAll()]
控制台信息是这样,但是读不到数据
from springboot-dynamicdatasource.
You can reference this document https://github.com/helloworlde/SpringBoot-DynamicDataSource/blob/master/Issues.md
from springboot-dynamicdatasource.
Related Issues (20)
- 在@Transactional的方法中切换数据源失败 HOT 1
- 测试数据的返回值 HOT 1
- 主从数据切换数据同步问题 HOT 2
- 没有注解实现切换吗 HOT 2
- Caused by: java.io.FileNotFoundException: class path resource [mapper/*.xml] cannot be opened because it does not exist HOT 1
- 关于动态增减数据源 HOT 1
- 能否通过数据库表的方式来配置多个数据源? HOT 8
- springboot2.0+版本无法切换slave数据源。 HOT 1
- 后期再追加多个数据库的问题 HOT 5
- 多类型数据源怎么配置方言呢
- java: 无法将类 java.lang.ThreadLocal<T>中的方法 withInitial应用到给定类型 HOT 1
- 按这种方式该怎么样实现事务呢 HOT 1
- 数据库上下文配置 HOT 1
- 在DAO上进行切片,没有办法切换数据库呀? 只能在servcie HOT 1
- SqlSessionFactoryBean异常报错 HOT 1
- spring mvc mybaits 怎样动态切换数据 HOT 1
- 配置文件关于mybatis配置问题
- where is the pom.xml HOT 2
- yml文件中配置mybatis.mapper-locations,启动报错 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from springboot-dynamicdatasource.