先说说问题,我在一个项目中jpa和elasticsearch共用了实体类,一启动就直接报错了,去stackoverflow找到了解决方案,在这里分享一下。
Repositories in Spring Data are datasource agnostic, meaning that JpaRepository and ElasticsearchRepository both roll up into Repository interface. When this is the case, then auto-configuration of Spring Boot will cause Spring Data JPA to try and configure a bean for each repository in the project that inherits any Spring Data Commons base repository.
To fix this problem you need to move your JPA repository and Elasticsearch repository to separate packages and make sure to annotate your @SpringBootApplication application class with:
- @EnableJpaRepositories
- @EnableElasticsearchRepositories
@SpringBootApplication