简体   繁体   English

使用Spring配置文件中的条目作为注释属性的值

[英]Using an entry from the Spring configuration file as value for annotation property

I'm trying to take out the name of the ElasticSearch indexName from the code and pull it into a config file. 我正在尝试从代码中取出ElasticSearch indexName的名称,并将其拉入配置文件。

@Document(indexName = "test", type = "file")
public class File {
***
}

The problem I'm running into is that I don't know how you/if you can put the "test" into a value in the .properties file and use it in the annotation. 我遇到的问题是,我不知道您如何将“测试”放入.properties文件中的值中,并在批注中使用它。

You can do this using: 您可以使用以下方法执行此操作:

@Document(indexName = "${keyname}", type = "file")

In your properties file: 在属性文件中:

keyname=test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM