在用户登录时动态更改数据源 [英] Change data source dynamically on user login
问题描述
我有一个具有以下要求的项目:
- 允许用户使用不同的模式, ;
- 根据规则动态路由数据源 - 例如,公司A中的用户应访问模式A,公司B中的用户应访问模式B;
- 验证用户的业务逻辑应该在一个业务组件 - EJB中,因为可以添加新的应用程序,并且该逻辑必须在Web应用程序之外。
我阅读了关于使用动态数据源路由。 CustomerContextHolder
有一个字段,它是 ThreadLocal
。是 ThreadLocal
保证用户A按照我的条件访问模式A?代码是线程安全吗?
我明白的方式是,您需要与数据源一起多次使用春天。 p>
可能你有一个春天的扩展可能有助于
https://github.com/mariofts/spring-multitenancy
I have a project that has the following requeriments:
- Allow users to login in the same Web Application using different schemas following a criteria;
- Dynamically route the datasource against a rule - for example, users in Company A should access schema A, users in Company B should access schema B;
- The business logic which authenticates the user`s should be in a business component - EJB, because new applications can be added and this logic must be outside the Web Application.
I read about using Dynamic Data Source Routing. The CustomerContextHolder
has a field which is ThreadLocal
. Is ThreadLocal
a guarantee that the user A will access the schema A following my criteria? Will the code be thread safe?
The way i understand is that you need multi tenency for spring along with datasource.
Probably you have have a look to spring extension which might help
https://github.com/mariofts/spring-multitenancy
这篇关于在用户登录时动态更改数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!