首页 > 解决方案 > Java / Spring在线程关闭后获取多租户程序的tenantId?

问题描述

我有一个 Java/Spring(没有 Spring 启动)程序,一旦前端加载,它基本上将tenantId 设置在 ThreadLocal 变量中,并执行其通常的多租户请求处理,这可能类似于本文https://medium.com /swlh/multi-tenancy-implementation-using-spring-boot-hibernate-6a8e3ecb251a

1) Accept the incoming connection, and authenticate the user if necessary.
2) Intercept the request and identify the tenant for which the user is issuing the request.
3) Establish a connection with the database or schema of the tenant.

我的问题是程序在设置它的 ThreadLocal 变量的线程关闭后一段时间查询tenantId(查询在超时时触发,因此当前执行的线程可能真的是任何东西)。有没有办法在它设置的线程关闭后仍然获取tenantId?请尝试给出一个简单/高级的答案,我不确定该程序中的所有内容是如何实际实现的。

标签: javaspringmulti-tenantthread-local

解决方案


推荐阅读