我引用了这个链接来实现两个数据源的springboot多租户-不同的数据库(尽管模式相同)-
https://anakiou.blogspot.in/2015/08/multi-tenant-application-with-spring.html
在我的应用程序中没有引入任何多线程之前,它工作得很好。
当我添加了一个ExecutorService来为csv文件中的每个记录在多个表中进行插入时,我看到新线程不包含rest服务调用使用的原始租户标识符的信息。
相反,它开始在新线程中使用默认租户。
编辑1:ExecutorService代码:尝试将当前租户设置为:
List<Future<Output>> futures = new ArrayList<Future<Output>>();
for (int j = 0; j < myList.size(); j++) {
final Output output= myList.get(j);
Future<Output> future = executorService.submit(new Callable<Output>() {
@Override
public Output call() throws Exception {
**TenantContext.setCurrentTenant(<current tenant goes here>);**
Output currentOutput= someService.executeQueries(output);
return currentOutput;
}
});
futures.add(future);
}