在用户登录时动态更改数据源 [英] Change data source dynamically on user login

查看:183
本文介绍了在用户登录时动态更改数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下要求的项目:


  1. 允许用户使用不同的模式, ;

  2. 根据规则动态路由数据源 - 例如,公司A中的用户应访问模式A,公司B中的用户应访问模式B;

  3. 验证用户的业务逻辑应该在一个业务组件 - EJB中,因为可以添加新的应用程序,并且该逻辑必须在Web应用程序之外。

我阅读了关于使用动态数据源路由 CustomerContextHolder 有一个字段,它是 ThreadLocal 。是 ThreadLocal 保证用户A按照我的条件访问模式A?代码是线程安全吗?

解决方案

我明白的方式是,您需要与数据源一起多次使用春天。 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

这篇关于在用户登录时动态更改数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆