Multithreading 为什么我在春天读不到mongodb的名字?
我有一个ThreadLocale,在其中我设置了一些值,我想在创建mongo文档时读取这些值Multithreading 为什么我在春天读不到mongodb的名字?,multithreading,mongodb,spring-boot,Multithreading,Mongodb,Spring Boot,我有一个ThreadLocale,在其中我设置了一些值,我想在创建mongo文档时读取这些值 @Service public class DocumentContext { private ThreadLocal<String> currentValue = new ThreadLocal<>(); public void setName(String documentName) {
@Service
public class DocumentContext {
private ThreadLocal<String> currentValue = new ThreadLocal<>();
public void setName(String documentName) {
currentValue.set(documentName);
}
public String getName() {
return currentValue.get();
}
}
现在我有了我的POJO类,我在其中使用如下:
@Data
@Document(collection="doc.#{docContext.getName()}.tableName")
class Entity{
}
但是,在mongo中,我得到的集合名称为:
doc..tablename
我期待着:
doc.value1.tablename
请建议我是否遗漏了什么。在您的筛选器中,您说的是
docContext.setCurrentTenant(col)代码>但不应该是setName(col)代码>?或者这只是问题中的一个输入错误。@Gregg抱歉,这是一个输入错误
@Data
@Document(collection="doc.#{docContext.getName()}.tableName")
class Entity{
}