Dor*_*ian 7 spring-mvc spring-data spring-boot spring-data-elasticsearch
是否可以动态地(在运行时)指定indexName
每个@Document
,例如,通过配置文件?或者是否可以使@Document
Spring环境(dev,prod)依赖?
谢谢!
小智 15
@Document注释不允许直接在参数中传递indexname.但是我找到了一个解决方法.
在我的配置类中,我创建了一个返回字符串的Bean.在这个字符串中,我用@Value注入了索引的名称:
@Value("${etrali.indexname}")
private String indexName;
@Bean
public String indexName(){
return indexName;
}
Run Code Online (Sandbox Code Playgroud)
之后可以将索引注入@Documentation注释,如下所示:
@Document(indexName="#{@indexName}",type = "syslog_watcher")
Run Code Online (Sandbox Code Playgroud)
它适用于我,我希望它会帮助你.
最好的祝福
归档时间: |
|
查看次数: |
5091 次 |
最近记录: |