Skip to content

关于切换不成功问题 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lishuanghe214 opened this issue Nov 3, 2020 · 3 comments
Closed

关于切换不成功问题 #17

lishuanghe214 opened this issue Nov 3, 2020 · 3 comments

Comments

@lishuanghe214
Copy link

private final String[] QUERY_PREFIX = {"list"};

控制台打印
Switch DataSource to [slave] in Method [List com.weiyin.streetlamp.menu.dao.MenuDao.listAll()]
Restore DataSource to [master] in Method [List com.weiyin.streetlamp.menu.dao.MenuDao.listAll()]

但是查询的还是主库中的数据,我配置的一主一次从

@lishuanghe214
Copy link
Author

我的没有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;
}

@lishuanghe214
Copy link
Author

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()]
控制台信息是这样,但是读不到数据

@helloworlde
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants