我用的是弹簧靴,冬眠逆流。我在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.persistence有PersonDAO和AddressDAO,还有实体。
我有两个道斯,
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同时适用于RevisionRepository和JpaRepository。
我跟踪了异常堆栈,
org.springframework.beans.factory.UnsatisfiedDependencyException:错误创建名为‘addressService’的bean :通过字段‘addressDAO’表示的不满意的依赖关系;嵌套异常是创建名为‘addressDAO’的bean时出现的org.springframework.beans.factory.BeanCreationException:错误: init方法调用失败;嵌套异常为org.springframework.data.mapping.PropertyReferenceException: dependency,类型为AddressEntity! 导致: org.springframework.beans.factory.BeanCreationException:错误创建名为‘addressDAO’的bean :调用init方法失败;嵌套异常是org.springframework.data.mapping.PropertyReferenceException:,没有为AddressEntity类型找到属性findAll! 原因: org.springframework.data.mapping.PropertyReferenceException:没有为AdressEntity类型找到属性findAll!
我是不是错过了任何配置。
发布于 2017-11-09 12:59:26
得到解决方案;)
需要创建两个单独的配置类,因为我们不能在同一个配置类上使用两个@EnableJpaRepositories。
因此创建了以下两个配置类,
@EnableJpaRepositories(basePackages = "com.example.jpa.dao")
class JpaConfig {}
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean, basePackages = "com.example.envers.dao")
class EnversConfig {}https://stackoverflow.com/questions/47172611
复制相似问题