【问题标题】:Combining Spring-Data for MongoDB and ElasticSearch结合 Spring-Data for MongoDB 和 ElasticSearch
【发布时间】:2016-04-02 17:20:47
【问题描述】:

我在努力

@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 注释,该错误就会消失。

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

【问题讨论】:

  • 你能附上GoalRepository代码吗?

标签: java spring mongodb spring-data-mongodb spring-data-elasticsearch


【解决方案1】:

在一个项目中使用多个 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,马克

【讨论】:

  • 谢谢。我知道问题出在哪里,但我不知道如何解决它。你为我缩短了很多。
猜你喜欢
  • 2018-08-24
  • 2021-04-24
  • 2014-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多