EnversRevisionRepositoryFactoryBean 不为 JPARepositories 创建 bean

EnversRevisionRepositoryFactoryBean dosenot create bean for JPARepositories

我正在使用 spring 引导,逆向休眠。我在 pom.xml

中有以下依赖
<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-envers</artifactId>
</dependency>

以下是我的环境配置。

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

}

所以包 com.example.persistencePersonDAOAddressDAO 以及实体。

我有以下两个 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!

我是否缺少任何配置。

找到解决方案 ;)

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

所以创建了以下两个配置classes,

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

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