spring-boot - EnversRevisionRepositoryFactoryBean 不为 JPARepositories 创建 bean

标签 spring-boot hibernate-envers spring-data-envers

我正在使用 spring boot,hibernate enverse。我在 pom.xml 中有以下依赖

<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-envers</artifactId>
</dependency>

以下是我的 envers 配置。

@Configuration
@EnableJpaRepositories(repositoryFactoryBeanClass = 
EnversRevisionRepositoryFactoryBean.class, basePackages = { 
"com.example.persistence" })
public class EnversConf
{

}

所以包 com.example.persistencePersonDAOAddressDAO 还有 Entities。

我有以下两个 DAO,

interface PersonDAO  extends RevisionRepository<PersonEntity, Integer, Integer>, JpaRepository<PersonEntity, Integer>{}

interface AddressDAO  extends JpaRepository<AddressEntity, Integer>{}

我有两个要审计的实体 PersonEntity 和我不想审计的 AddressEntity

现在我有以下两个服务,

class PersonServiceImpl implements PersonService{
    @Autowire PersonDAO personDAO;
}

class AddressServiceImpl implements AddressService{
    @Autowire AddressDAO addressDAO;
}

当我添加 @EnableJpaRepositories(...) 配置时,它无法为 AddressDAO 获取 bean。我认为 EnversRevisionRepositoryFactoryBean 适用于 RevisionRepositoryJpaRepository

我得到了以下异常堆栈跟踪,

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addressService': Unsatisfied dependency expressed through field 'addressDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addressDAO': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type AddressEntity!

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addressDAO': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type AddressEntity!

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type AdressEntity!

我是否缺少任何配置。

最佳答案

得到解决方案;)

需要创建两个单独的配置类,因为我们不能在同一个配置类上使用两个 @EnableJpaRepositories。

因此创建了以下两个配置类,

@EnableJpaRepositories(basePackages = "com.example.jpa.dao")
class JpaConfig {}

@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean, basePackages = "com.example.envers.dao")
class EnversConfig {}

关于spring-boot - EnversRevisionRepositoryFactoryBean 不为 JPARepositories 创建 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47172611/

相关文章:

spring-boot - Spring Boot 应用程序在一天后卡住

java - Spring Boot(用户 '' @'localhost' 对数据库 'myappdb' 的访问被拒绝)

java - entityManager.flush()会清除二级缓存吗?

java - 使用 hibernate-envers 时,AUD 表中的所有 @Version 字段均为 null,但在实体中 - 表已填充好吗?

spring-boot - 循环遍历 jpa streamresult 的项目并调用更新服务。 Envers 对所有项目创建修订,而不是为每个项目创建修订

spring-boot - 为什么 Spring Data Envers 修订类型返回 UNKNOWN?

tomcat - Spring Boot War 文件在 ec2 上获取 404

java - Hibernate启用自定义修订版实体

java - 如何自定义hibernate @ElementCollection envers审计表名称?