尝试从类JsonTypeDescriptor访问方法JavaXMember.getJavaType()

ss2ws0br  于 2022-12-21  发布在  Java
关注(0)|答案(1)|浏览(122)

我有一个正在工作的Sping Boot 项目,它使用Spring Data JPA和Hibernate作为JPA实现。有一天运行这个项目时,我遇到了以下异常:

java.lang.IllegalAccessError: tried to access method org.hibernate.annotations.common.reflection.java.JavaXMember.getJavaType()Ljava/lang/reflect/Type; from class com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor

以下是完整的堆栈跟踪:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalAccessError: tried to access method org.hibernate.annotations.common.reflection.java.JavaXMember.getJavaType()Ljava/lang/reflect/Type; from class com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
    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 kz.rs.promo.PromoApp.main(PromoApp.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalAccessError: tried to access method org.hibernate.annotations.common.reflection.java.JavaXMember.getJavaType()Ljava/lang/reflect/Type; from class com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor
    at com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor.setParameterValues(JsonTypeDescriptor.java:69)
    at com.vladmihalcea.hibernate.type.json.JsonBinaryType.setParameterValues(JsonBinaryType.java:91)
    at org.hibernate.type.TypeFactory.injectParameters(TypeFactory.java:142)
    at org.hibernate.type.TypeFactory.type(TypeFactory.java:125)
    at org.hibernate.type.TypeFactory.byClass(TypeFactory.java:99)
    at org.hibernate.type.TypeResolver.heuristicType(TypeResolver.java:112)
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:440)
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:422)
    at org.hibernate.mapping.Property.isValid(Property.java:226)
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:597)
    at org.hibernate.mapping.RootClass.validate(RootClass.java:265)
    at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:451)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:889)
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:360)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:382)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:371)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:336)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
    ... 19 common frames omitted

我不知道是什么导致了这个异常,我没有编辑配置(应用程序属性文件,pom.xml,env变量)。这是依赖项的部分列表,与hib相关,使用命令mvn dependency:list列出:

com.vladmihalcea:hibernate-types-52:jar:2.19.2:compile
org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
org.hibernate:hibernate-entitymanager:jar:5.2.12.Final:compile
org.hibernate:hibernate-envers:jar:5.2.12.Final:compile
org.hibernate:hibernate-validator:jar:5.3.6.Final:compile
org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
org.hibernate:hibernate-core:jar:5.2.12.Final:compile
com.fasterxml.jackson.datatype:jackson-datatype-hibernate5:jar:2.8.10:compile
com.hazelcast:hazelcast-hibernate52:jar:1.2.2:compile

Java版本:

openjdk version "1.8.0_302"
OpenJDK Runtime Environment Corretto-8.302.08.1 (build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM Corretto-8.302.08.1 (build 25.302-b08, mixed mode)
qyyhg6bp

qyyhg6bp1#

我也有同样的问题。我试着用

implementation 'com.vladmihalcea:hibernate-types-52:2.21.0'

Mapapache Pair类,但得到的错误与您完全相同。
通过反复试验,我发现添加到gradle

implementation 'org.hibernate.common:hibernate-commons-annotations:5.1.0.Final'

错误消失,应用程序启动。
我用

azul java-1.8.0_322; 
spring boot version 2.1.4.RELEASE; 
hibernate version 5.6.9.Final

我确信这个错误是由不兼容的库版本引起的。

相关问题