同时使用@Document和@Entity

时间:2019-03-04 16:39:56

标签: spring spring-boot elasticsearch nosql

我尝试在同一Entity类上将@Document与@Entity一起使用,但是在实现两个存储库(ElasticSearchRepository和CrudRepository)时出现以下错误
The bean 'esRepo', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.

1 个答案:

答案 0 :(得分:1)

我认为这与Spring Data JPA组件扫描程序有关,请尝试添加以下配置类,并将两个存储库放在不同的软件包中。
用于Elasticsearch存储库:
@Configuration @EnableElasticsearchRepositories(basePackages = "org.ala.springdataes.esrepository") public class ESConfig { }
对于JPA仓库:
@Configuration @EnableJpaRepositories("org.ala.springdataes.repository") public class RepoConfiguration { }