我正在努力
@org.springframework.data.mongodb.core.mapping.Document(collection = "goal")
@org.springframework.data.elasticsearch.annotations.Document(indexName = "goal")
public class Goal implements Serializable {
....}
但这给了我:
Error creating bean with name 'goalRepository':
Invocation of init method failed; nested exception is
org.springframework.data.mapping.PropertyReferenceException:
No property insert found for type Goal! ->
顺便说一句:当我向 Goal 添加名为“insert”的属性或从目标中删除 elasticsearch 注释时,该错误就会消失。
目标存储库是:
package org.jhipster.mongo.repository;
import org.jhipster.mongo.domain.Goal;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface GoalRepository extends MongoRepository<Goal,String> {
}
最佳答案
在一个项目中使用多个 Spring Data 模块是可能的,但需要注意设置。
类路径上有多个 Spring Data 模块可以实现严格的配置,这是 Spring Data 区分存储库职责所必需的。这主要通过注释以及特定存储库是否适合类型层次结构来完成。在您的例子中,Goal
使用 MongoDB 和 Elasticsearch 注释进行注释,因此这两个模块都渴望实现存储库。
到目前为止,唯一的方法是将存储库保存在不同的包中,并将这些包用作@Enable…Repositories
中的基础包。假设您的 Elasticsearch 存储库位于 org.jhipster.elasticsearch.repository 中,您的应用程序配置可能如下所示:
@EnableMongoRepositories("org.jhipster.mongo.repository")
@EnableElasticsearchRepositories("org.jhipster.elasticsearch.repository")
@SpringBootApplication
public class SpringBootApplication { … }
马克·HTH
关于java - 结合 Spring-Data for MongoDB 和 ElasticSearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36376447/