问题描述
在我的Spring Boot应用程序中,我有一个@Setting注释指向设置JSON文件,但似乎被完全忽略了。
In my Spring Boot application I have a @Setting annotation pointing to a settings JSON file but it seems to be completely ignored.
@Setting(settingPath = "/settings/elasticsearch-settings.json")
@Document(indexName = "hermes", type = "client", shards = 1, replicas = 0, refreshInterval = "-1")
public class Client {
@Id
private String externalId;
private String name;
private String surname;
private String taxNumber;
private String uid;
//getters and setter intentionally left out
}
我的设置文件位于:
src/main/resources/settings/elasticsearch-settings.json
文件内容如下:
{
"analysis": {
"analyzer": {
"my_ngram_analyzer": {
"tokenizer": "my_ngram_tokenizer"
}
},
"tokenizer": {
"my_ngram_tokenizer": {
"type": "nGram",
"min_gram": "2",
"max_gram": "3",
"token_chars": [
"letter",
"digit"
]
}
}
}
}
当我使用Elasticsearch REST API运行此命令时,它会更改设置没问题,所以我认为JSON本身是有效的。但是,即使我放置了无效的JSON或一起删除了文件,我也一无所获,Spring也没有警告或错误。这就是为什么我的猜测是完全忽略了注释。
When I run this using Elasticsearch REST api it changes the settings without a problem, so I guess the JSON itself is valid. But even when i put an invalid JSON, or delete the file all together, I get nothing, no warning or error from Spring. That is why my guess is that the annotation is completely ignored.
如果可能与此相关,那么我还有一个Elasticsearch配置类,我可以使用它来公开客户端在端口9200上进行注释。
If it might have anything to do with this, I also have an Elasticsearch configuration class that I use to expose the client on port 9200. It is annotated with:
@EnableConfigurationProperties(ElasticsearchProperties.class)
然后:
@EnableAutoConfiguration(exclude= { ElasticsearchAutoConfiguration.class })
我的主类的注释。
推荐答案
您的 elasticsearch-settings.json
文件缺少索引
元素。改为这样尝试:
Your elasticsearch-settings.json
file is missing the index
element. Try like this instead:
{
"index": {
"analysis": {
"analyzer": {
"my_ngram_analyzer": {
"tokenizer": "my_ngram_tokenizer"
}
},
"tokenizer": {
"my_ngram_tokenizer": {
"type": "nGram",
"min_gram": "2",
"max_gram": "3",
"token_chars": [
"letter",
"digit"
]
}
}
}
}
}
这篇关于在Spring Boot中将忽略Elasticsearch的@Setting注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!