解决Spring Data JPA与Spring Data Elasticsearch 冲突问题

本文介绍了在项目中同时使用Spring Data JPA和Spring Data Elasticsearch时遇到的实体类冲突问题,启动应用报错。解决方案是将JPA和Elasticsearch的Repository分别放在不同包下,并在@SpringBootApplication注解的类上添加@EnableJpaRepositories和@EnableElasticsearchRepositories注解,以避免自动配置导致的问题。
摘要由CSDN通过智能技术生成

    先说说问题,我在一个项目中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
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值