Pra*_*kar 1 hibernate-envers spring-boot spring-data-envers
我使用的是弹簧靴,冬眠相反。我在pom.xml中具有以下依赖性
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-envers</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
以下是我的envers配置。
@Configuration
@EnableJpaRepositories(repositoryFactoryBeanClass =
EnversRevisionRepositoryFactoryBean.class, basePackages = {
"com.example.persistence" })
public class EnversConf
{
}
Run Code Online (Sandbox Code Playgroud)
因此,包com.example.persistence具有PersonDAO和AddressDAO实体。
我有两个DAO,
interface PersonDAO extends RevisionRepository<PersonEntity, Integer, Integer>, JpaRepository<PersonEntity, Integer>{}
interface AddressDAO extends JpaRepository<AddressEntity, Integer>{}
Run Code Online (Sandbox Code Playgroud)
我有两个PersonEntity要审核的实体,而我不想AddressEntity审核。
现在,我有以下两项服务,
class PersonServiceImpl implements PersonService{
@Autowire PersonDAO personDAO;
}
class AddressServiceImpl implements AddressService{
@Autowire AddressDAO addressDAO;
}
Run Code Online (Sandbox Code Playgroud)
当我添加@EnableJpaRepositories(...)配置时,它无法获取bean AddressDAO。我认为EnversRevisionRepositoryFactoryBean对... RevisionRepository和JpaRepository。
我得到了异常堆栈跟踪,
org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“ addressService”的bean时出错:通过字段“ addressDAO”表示的不满足的依赖关系;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'addressDAO'的bean时出错:调用init方法失败;嵌套的异常是org.springframework.data.mapping.PropertyReferenceException:没有找到类型为AddressEntity的属性findAll!
由以下原因引起:org.springframework.beans.factory.BeanCreationException:创建名称为'addressDAO'的bean时出错:调用init方法失败;嵌套的异常是org.springframework.data.mapping.PropertyReferenceException:没有找到类型为AddressEntity的属性findAll!
由以下原因引起:org.springframework.data.mapping.PropertyReferenceException:没有找到类型AdressEntity的属性findAll!
我是否缺少任何配置。
得到了解决方案;)
需要创建两个单独的配置类,因为我们不能在同一配置类上使用两个@EnableJpaRepositories。
因此,创建了以下两个配置类,
@EnableJpaRepositories(basePackages = "com.example.jpa.dao")
class JpaConfig {}
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean, basePackages = "com.example.envers.dao")
class EnversConfig {}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
858 次 |
| 最近记录: |