2

我想结合弹簧数据的MongoDB和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 name 'goalRepository': 
Invocation of init method failed; nested exception is 
org.springframework.data.mapping.PropertyReferenceException: 
No property insert found for type Goal! -> 

BTW:我添加的属性的名称。该错误就会消失“插入'到目标或我从目标中删除elasticsearch注释。

的GoalRepository是:

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> {  
} 
+0

你能附上'GoalRepository'代码呢? –

回答

1

使用多个数据春季模块在一个项目中是可能的,但需要有关设置的东西了关注。

在类路径上拥有多个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 { … } 

心连心,马克