springboot 学习mybatis下mysql的读写分离
269941633 / spring-boot-mybatis-mysql-write-read Goto Github PK
View Code? Open in Web Editor NEWspringboot 学习mybatis+mysql读写分离(一写多读)+事务
springboot 学习mybatis+mysql读写分离(一写多读)+事务
dao层query方法List query(@param("userName")String userName);
返回的是User集合,而mapper.xml写的返回是User
是不是写错了
@bean(name = "readDataSource01")
@ConfigurationProperties(prefix = "spring.druid.read01")
public DataSource readDataSourceOne() {
log.info("-------------------- read01 DataSourceOne init ---------------------");
return DataSourceBuilder.create().type(dataSourceType).build();
}
dug这里使用@ConfigurationProperties(prefix = "spring.druid.read01")并没有将数据库配置注入datasource里面。本来我用的是prefix = "spring.datasource.read01"但是这样会报错druid url not set,所以我换成"spring.druid.read01",但是会报错WrongArgumentException: The database URL cannot be null。 debug发现没有将数据库配置注入datasource里面。
mysql主从复制,读写分离,启用事务管理,在service层做切面时,controller调用的每个service方法都必须指明数据源注解。AopContext.currentProxy()固然可以获取数据源,可是在controller去调用service不带注解的方法(如wirteAndRead(),readAndWirte())的时候会先判断数据源,再往下执行。这时候,该方法将会出现未指定明确数据源的报错。也就是在执行wirteAndRead和readAndWirte的里面的代码前已经报错。
可以为service指定数据源,也可以在数据源配置中修改”typeKey 为空时指定默认数据源“。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.