Spring Data Envers-PropertyReferenceException:找不到属性Foo类型的修订版

时间:2018-07-25 12:50:22

标签: java spring hibernate hibernate-envers spring-data-envers

我确实有一个Sprint-Boot应用程序,并尝试向项目添加from tkinter import * root = Tk() menubar = Menu(root) tearoff = Menu(menubar, tearoff=1) tearoff.add_command(label="Tearoff") menubar.add_cascade(label="Tearoff", menu=tearoff) notearoff = Menu(menubar, tearoff=0) notearoff.add_command(label="No Tearoff") menubar.add_cascade(label="No Tearoff", menu=notearoff) root.config(menu=menubar) root.mainloop() 或更具体的hibernate-envers

所以我添加了

spring-data-envers

Revision实体已成功生成/创建并保存,直到我尝试使用RevisionRepository。现在我得到了我没有想到的错误。

我创建了一个新的配置,例如:

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

我通过以下方式扩展了我已经在使用的CrudRepository:

@Configuration
@EntityScan(basePackages = {"com.package.entities"})
@EnableJpaRepositories(basePackages = "com.package.repos",
repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
public class EnversConfiguration {}

任何时候我尝试启动该应用程序时都会告诉我:

@Repository
@Transactional
public interface FooRepository extends RevisionRepository<Foo, Long, Long>, CrudRepository<Foo, Long> {
    ...
}

所包含的配置如下:

SpringApplication.reportFailure - Application startup failed
java.lang.IllegalArgumentException: Attribute 'repositoryFactoryBeanClass' for annotation [unknown] was not resolvable due to exception [java.lang.ClassNotFoundException: org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean]
    at org.springframework.core.annotation.AnnotationAttributes.assertNotException(AnnotationAttributes.java:544)
    at org.springframework.core.annotation.AnnotationAttributes.getRequiredAttribute(AnnotationAttributes.java:429)
    at org.springframework.core.annotation.AnnotationAttributes.getClass(AnnotationAttributes.java:293)
    at org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.getRepositoryFactoryBeanName(AnnotationRepositoryConfigurationSource.java:216)
    at org.springframework.data.repository.config.DefaultRepositoryConfiguration.getRepositoryFactoryBeanName(DefaultRepositoryConfiguration.java:163)
    at org.springframework.data.repository.config.RepositoryBeanDefinitionBuilder.build(RepositoryBeanDefinitionBuilder.java:85)
    at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:125)
    at org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions(RepositoryBeanDefinitionRegistrarSupport.java:83)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:359)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:143)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:320)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at com.package.web.WebApplication.main(WebApplication.java:49)

所以我发现某个地方暗示@Import({ ... , EnversConfiguration.class}) public class WebApplication extends SpringBootServletInitializer implements ApplicationListener<ContextRefreshedEvent> { ... } 不需要两次,因为我已经有了JpaRepositories的另一个配置,因此我从@EnableJpaRepositories(basePackages = "com.package.repos"删除了它

此后,我得到此错误:

EnversConfiguration

由于在FooService中对FooRepository进行了@Autowired注入:

Caused by: java.lang.NoClassDefFoundError: org/joda/time/DateTime
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethod(Class.java:2128)
    at org.springframework.core.LocalVariableTableParameterNameDiscoverer$LocalVariableTableVisitor.resolveMember(LocalVariableTableParameterNameDiscoverer.java:245)
    at org.springframework.core.LocalVariableTableParameterNameDiscoverer$LocalVariableTableVisitor.visitEnd(LocalVariableTableParameterNameDiscoverer.java:231)
    at org.springframework.asm.ClassReader.readMethod(ClassReader.java:1172)
    at org.springframework.asm.ClassReader.accept(ClassReader.java:729)
    at org.springframework.asm.ClassReader.accept(ClassReader.java:527)
    at org.springframework.core.LocalVariableTableParameterNameDiscoverer.inspectClass(LocalVariableTableParameterNameDiscoverer.java:114)
    at org.springframework.core.LocalVariableTableParameterNameDiscoverer.getParameterNames(LocalVariableTableParameterNameDiscoverer.java:87)
    at org.springframework.core.PrioritizedParameterNameDiscoverer.getParameterNames(PrioritizedParameterNameDiscoverer.java:64)
    at org.springframework.data.mapping.model.PreferredConstructorDiscoverer.buildPreferredConstructor(PreferredConstructorDiscoverer.java:115)
    at org.springframework.data.mapping.model.PreferredConstructorDiscoverer.<init>(PreferredConstructorDiscoverer.java:75)
    at org.springframework.data.mapping.model.PreferredConstructorDiscoverer.<init>(PreferredConstructorDiscoverer.java:49)
    at org.springframework.data.repository.query.ReturnedType$ReturnedClass.detectConstructorParameterNames(ReturnedType.java:286)
    at org.springframework.data.repository.query.ReturnedType$ReturnedClass.<init>(ReturnedType.java:233)
    at org.springframework.data.repository.query.ReturnedType.of(ReturnedType.java:63)
    at org.springframework.data.repository.query.ResultProcessor.<init>(ResultProcessor.java:81)
    at org.springframework.data.repository.query.ResultProcessor.<init>(ResultProcessor.java:64)
    at org.springframework.data.repository.query.QueryMethod.<init>(QueryMethod.java:100)
    at org.springframework.data.jpa.repository.query.JpaQueryMethod.<init>(JpaQueryMethod.java:89)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:77)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:449)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:222)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263)
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:101)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
    ... 133 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.joda.time.DateTime
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 162 common frames omitted

请确保我将以下依赖项添加到pom.xml并检查包装是否设置为“ war”

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fooServiceImpl': Unsatisfied dependency expressed through field 'fooRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fooRepository': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/joda/time/DateTime

更新1 (原始标题:ClassNotFoundException:EnversRevisionRepositoryFactoryBean或org / joda / time / DateTime)

所以我玩了一下,并更改了导入配置的顺序:

<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
</dependency>

然后,我将FooRepository拆分为FooRevisionRepository,而FooRepository仅保留为CrudRepository:

@Import({EnversConfiguration.class, DataAccessConfiguration.class, ...})
public class WebApplication

不,启动时出现此错误

@Repository
public interface FooRevisionRepository extends RevisionRepository<Foo, Long, Integer> {}

1 个答案:

答案 0 :(得分:0)

配置jpa存储库: @EnableJpaRepositories(         repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class )