[英]Combining Spring-Data for MongoDB and 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! ->
順便說一句:只要我向 Goal 添加名為“插入”的屬性或從目標中刪除 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,馬克
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.