Skip to content
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

手动切换数据源,无法对同一个mapper方法,进行多次数据源切换 #696

Closed
wangwangwangBoy opened this issue Jan 2, 2025 · 1 comment

Comments

@wangwangwangBoy
Copy link

JDK Version(required): 8

SpringBoot Version(required): 2.7.14

dynamic-datasource-spring-boot-starter Version(required):3.3.2

druid Version(optional):HikariCP-4.0.5

Describe what happened

如题:
多租场景下,做部分聚合操作,需要从不同租户的数据库中拿目标数据;

`DynamicDataSourceContextHolder.push("A");//A租户数据源
jdbcTemplate.queryForList("select * from user");

DynamicDataSourceContextHolder.push("B");//B租户数据源
jdbcTemplate.queryForList("select * from user");`

上述代码顺序执行,发现执行B数据源操作时,仍然使用A租户的数据源,使用的同一个sqlSession

Expected Result:

切换到B后,能去B对应的库中查询数据

Actual Result:
仍然在A的库中查数据

  • Step 3
@huayanYu
Copy link
Member

huayanYu commented Jan 2, 2025

请提供复现程序

@huayanYu huayanYu closed this as completed Jan 7, 2025
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