【问题标题】:Spring Data JDBC and Hibernate JPA in One Project一个项目中的 Spring Data JDBC 和 Hibernate JPA
【发布时间】:2020-11-12 07:25:37
【问题描述】:

是否可以在一个项目中同时使用 Spring Data JDBC 和 Spring Data 休眠?

@SpringBootApplication
@ComponentScan(basePackages = {"com.meteor", "com.test"})
//@EnableMeteorTransactionManagement
@EnableFeignClients(basePackages = "com.meteor.keycloak.utils")
@EnableJdbcRepositories(basePackages = {"com.test.coral"})
@EnableJpaRepositories(basePackages = {"com.meteor.coral"}, repositoryBaseClass = MeteorAdapterRepositoryImpl.class)

应用上下文似乎没有看到 bean。

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.test.coral.resources.useradministration.domain.AppUserRepo' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value="appUserRepo")}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1714)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1270)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1224)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
    ... 29 more

谢谢

【问题讨论】:

  • 我也看到了这些。 Spring Data JDBC - 无法安全地识别存储库候选接口 com.sxi.coral.resources.useradministration.domain.AppUserRepo 的存储分配。如果您希望此存储库成为 JDBC 存储库,请考虑使用以下注释之一来注释您的实体:org.springframework.data.relational.core.mapping.Table。

标签: spring-boot spring-data-jpa spring-data-jdbc


【解决方案1】:

问题是表注释映射。

@Data
@Entity
@Table(name = "m_appuser", uniqueConstraints = @UniqueConstraint(columnNames = { "username" }, name = "username_org"))
@org.springframework.data.relational.core.mapping.Table

我需要添加 Spring Data JDBC Table 注释才能使其工作。

【讨论】:

    猜你喜欢
    • 2017-07-17
    • 2019-07-20
    • 2023-04-08
    • 2014-07-03
    • 2017-08-08
    • 2018-08-11
    • 1970-01-01
    • 1970-01-01
    • 2015-08-27
    相关资源
    最近更新 更多