且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在用户登录时动态更改数据源

更新时间:2023-09-21 18:39:16

我明白的方式是,您需要与数据源一起多次使用春天。 p>

可能你有一个春天的扩展可能有助于



https://github.com/mariofts/spring-multitenancy


I have a project that has the following requeriments:

  1. Allow users to login in the same Web Application using different schemas following a criteria;
  2. 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;
  3. 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