我开始了一个项目,其中我同时使用了 Mongo、Elasticsearch 和 spring boot。
单独使用这两种技术,该项目都可以正常工作。然而,两者结合在一起,它们就会发生冲突。我看到了这篇似乎与我的问题相似的特定文章。 https://jira.spring.io/browse/DATAES-57 所以我试了一下,问题仍然存在。
我把这些放在主课上
@EnableAutoConfiguration(exclude = MongoRepositoriesAutoConfiguration.class)
@EnableMongoRepositories(basePackages = "com.searchizi.mongo.repository")
@EnableElasticsearchRepositories(basePackages = "com.searchizi.elasticsearch.repository")
@ComponentScan
public class Application implements CommandLineRunner { … }
异常跟踪的缩写形式是这样
该类SearchiziUser
在com.searchizi.mongo.model
包中。它不在 Elasticsearch 扫描路径上。
Caused by: java.lang.IllegalArgumentException: Unable to identify index name. SearchiziUser is not a Document. Make sure the document class is annotated with @Document(indexName="foo")
at org.springframework.util.Assert.isTrue(Assert.java:65)
at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.getPersistentEntityFor(ElasticsearchTemplate.java:869)
at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.createIndexIfNotCreated(ElasticsearchTemplate.java:684)
at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.createIndex(ElasticsearchTemplate.java:135)
at org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository.createIndex(AbstractElasticsearchRepository.java:80)
at org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository.<init>(AbstractElasticsearchRepository.java:72)
at org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.<init>(SimpleElasticsearchRepository.java:36)
每个存储库类型的扫描应该分开,但显然不是。知道该怎么做吗?