Java 结合用于MongoDB和ElasticSearch的Spring数据
我正在努力Java 结合用于MongoDB和ElasticSearch的Spring数据,java,spring,mongodb,spring-data-mongodb,
spring-data-elasticsearch,Java,Spring,Mongodb,Spring Data Mongodb,
spring Data Elasticsearch,我正在努力 @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 n
@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! ->
顺便说一句:只要我将名为“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> {
}
package org.jhipster.mongo.repository;
导入org.jhipster.mongo.domain.Goal;
导入org.springframework.data.mongodb.repository.MongoRepository;
公共接口目标存储扩展了MongoRepository{
}
在一个项目中使用多个Spring数据模块是可能的,但需要注意设置
在类路径上有多个Spring数据模块可以实现Spring数据区分存储库责任所需的严格配置。这主要通过注释以及特定存储库是否适合类型层次结构来完成。在您的例子中,Goal
使用MongoDB和Elasticsearch注释进行注释,因此这两个模块都迫切需要实现存储库
到目前为止,唯一的方法是将存储库保存在不同的包中,并将这些包用作@Enable…repositories
中的基本包。假设您的Elasticsearch回购位于org.jhipster.Elasticsearch.repository
中,您的应用程序配置可能如下所示:
@EnableMongoRepositories("org.jhipster.mongo.repository")
@EnableElasticsearchRepositories("org.jhipster.elasticsearch.repository")
@SpringBootApplication
public class SpringBootApplication { … }
嗯,马克你能不能也附上
GoalRepository
code?