如何解决 ‘javax.persistence.PersistenceContext does not match signer information’ 问题?

huangapple go评论72阅读模式
英文:

How to resolve the 'javax.persistence.PersistenceContext does not match signer information' problem?

问题

I have a spring-mvc maven-based web project running on Tomcat7.
这是我在运行Application.class时遇到的错误。
我应该如何解决签名信息不匹配的问题,以及指向哪个包,我已经提供了我的pom文件。

错误信息部分:

java.lang.SecurityException: class "javax.persistence.PersistenceContext"'s signer information does not match signer information of other classes in the same package

Pom文件中的依赖部分:

<dependencies>
    <!-- 其他依赖 -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <!-- 更多依赖 ... -->
</dependencies>

如果需要更多信息,请提供。

英文:

I have a spring-mvc maven-based web project running on Tomcat7.
This is the error I'm getting when i run the Application.class.
How can i solve the singer that is not matching and which package is being referred to, have provided my pom below

java.lang.SecurityException: class &quot;javax.persistence.PersistenceContext&quot;&#39;s signer information does not match signer information of other classes in the same package
	at java.lang.ClassLoader.checkCerts(ClassLoader.java:898)
	at java.lang.ClassLoader.preDefineClass(ClassLoader.java:668)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:761)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
	at org.springframework.core.type.classreading.MergedAnnotationReadingVisitor.get(MergedAnnotationReadingVisitor.java:138)
	at org.springframework.core.type.classreading.SimpleMethodMetadataReadingVisitor.visitAnnotation(SimpleMethodMetadataReadingVisitor.java:74)
	at org.springframework.asm.ClassReader.readMethod(ClassReader.java:1394)
	at org.springframework.asm.ClassReader.accept(ClassReader.java:718)
	at org.springframework.asm.ClassReader.accept(ClassReader.java:401)
	at org.springframework.core.type.classreading.SimpleMetadataReader.&lt;init&gt;(SimpleMetadataReader.java:49)
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
	at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:86)
	at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:73)
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81)
	at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:112)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:345)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140)
	at com.touhid.onlineshop.Application.main(Application.java:19)

The dependecies in my pom file

&lt;dependencies&gt;
&lt;!-- Other--&gt;
&lt;dependency&gt;
&lt;groupId&gt;log4j&lt;/groupId&gt;
&lt;artifactId&gt;log4j&lt;/artifactId&gt;
&lt;version&gt;1.2.17&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;jstl&lt;/groupId&gt;
&lt;artifactId&gt;jstl&lt;/artifactId&gt;
&lt;version&gt;1.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;taglibs&lt;/groupId&gt;
&lt;artifactId&gt;standard&lt;/artifactId&gt;
&lt;version&gt;1.1.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;cglib&lt;/groupId&gt;
&lt;artifactId&gt;cglib&lt;/artifactId&gt;
&lt;version&gt;3.2.4&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.aspectj&lt;/groupId&gt;
&lt;artifactId&gt;aspectjtools&lt;/artifactId&gt;
&lt;version&gt;1.6.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.github.tomakehurst&lt;/groupId&gt;
&lt;artifactId&gt;wiremock-standalone&lt;/artifactId&gt;
&lt;version&gt;2.18.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.google.gwt&lt;/groupId&gt;
&lt;artifactId&gt;gwt-user&lt;/artifactId&gt;
&lt;version&gt;2.1.0-8215&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;jboss.web&lt;/groupId&gt;
&lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
&lt;version&gt;3.0.0.alpha-25&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.logging&lt;/groupId&gt;
&lt;artifactId&gt;jboss-logging&lt;/artifactId&gt;
&lt;version&gt;3.4.1.Final&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt;
&lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;2.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt;
&lt;artifactId&gt;javax.persistence&lt;/artifactId&gt;
&lt;version&gt;2.2.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt;
&lt;artifactId&gt;org.eclipse.persistence.jpa&lt;/artifactId&gt;
&lt;version&gt;2.7.3&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;javax&lt;/groupId&gt;
&lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
&lt;version&gt;7.0&lt;/version&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
&lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
&lt;version&gt;1.0.2.Final&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- SpringFramework--&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework&lt;/groupId&gt;
&lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
&lt;version&gt;5.2.8.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.webflow&lt;/groupId&gt;
&lt;artifactId&gt;spring-webflow&lt;/artifactId&gt;
&lt;version&gt;2.5.1.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
&lt;version&gt;2.3.2.RELEASE&lt;/version&gt;
&lt;exclusions&gt;
&lt;exclusion&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
&lt;artifactId&gt;spring-security-core&lt;/artifactId&gt;
&lt;version&gt;5.3.4.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework&lt;/groupId&gt;
&lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
&lt;version&gt;5.2.8.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
&lt;artifactId&gt;spring-data-commons&lt;/artifactId&gt;
&lt;version&gt;2.3.2.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
&lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
&lt;version&gt;5.3.4.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
&lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
&lt;version&gt;2.3.2.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
&lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
&lt;version&gt;5.3.4.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- Database--&gt;
&lt;dependency&gt;
&lt;groupId&gt;mysql&lt;/groupId&gt;
&lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
&lt;version&gt;8.0.21&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
&lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
&lt;version&gt;5.1.3.Final&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
&lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
&lt;version&gt;5.4.19.Final&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
&lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
&lt;version&gt;5.4.19.Final&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.zaxxer&lt;/groupId&gt;
&lt;artifactId&gt;HikariCP&lt;/artifactId&gt;
&lt;version&gt;3.3.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- commons--&gt;
&lt;dependency&gt;
&lt;groupId&gt;commons-fileupload&lt;/groupId&gt;
&lt;artifactId&gt;commons-fileupload&lt;/artifactId&gt;
&lt;version&gt;1.2.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;commons-io&lt;/groupId&gt;
&lt;artifactId&gt;commons-io&lt;/artifactId&gt;
&lt;version&gt;2.4&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- javax--&gt;
&lt;dependency&gt;
&lt;groupId&gt;javax.validation&lt;/groupId&gt;
&lt;artifactId&gt;validation-api&lt;/artifactId&gt;
&lt;version&gt;2.0.1.Final&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;javax.servlet&lt;/groupId&gt;
&lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
&lt;version&gt;4.0.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
&lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
&lt;version&gt;2.3.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- fasterxml--&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
&lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
&lt;version&gt;2.11.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
&lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
&lt;version&gt;2.11.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
&lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
&lt;version&gt;2.11.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- slf4j--&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.slf4j&lt;/groupId&gt;
&lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
&lt;version&gt;1.7.5&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.slf4j&lt;/groupId&gt;
&lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
&lt;version&gt;1.7.5&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework&lt;/groupId&gt;
&lt;artifactId&gt;spring-test&lt;/artifactId&gt;
&lt;version&gt;5.1.8.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;

If additional information is required on this issue i will provide it.

答案1

得分: 3

背景 -
导致此异常的原因是您的类路径中有多个JAR文件引用了不同版本的JPA规范,而这些JPA规范由不同的JPA提供者(实现)提供。

解决方案 -

从您的 pom.xml 文件中移除以下依赖项。

  • <dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.1-api</artifactId>
    <version>1.0.2.Final</version>
    </dependency>
  • <dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>javax.persistence</artifactId>
    <version>2.2.1</version>
    </dependency>
  • <dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.jpa</artifactId>
    <version>2.7.3</version>
    </dependency>

这将导致仅剩下一个JAR文件,其中定义了 javax.persistence.PersistenceContext,即:

  • javax.persistence-api-2.2.jar,由 Hibernate ORM 提供程序 hibernate-core-5.4.19.jar 在运行时引用。

通过这些更改,您可以清理类路径并解决您遇到的运行时错误。

英文:

Background

The reason for this exception is that you have multiple jar files in your class path that reference the JPA specification in multiple versions by different JPA providers (implementations).

Solution

Remove the following dependencies from your pom.xml file.

  • &lt;dependency&gt;
    &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
    &lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
    &lt;version&gt;1.0.2.Final&lt;/version&gt;
    &lt;/dependency&gt;
    
  • &lt;dependency&gt;
    &lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt;
    &lt;artifactId&gt;javax.persistence&lt;/artifactId&gt;
    &lt;version&gt;2.2.1&lt;/version&gt;
    &lt;/dependency&gt;
    
  • &lt;dependency&gt;
    &lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt;
    &lt;artifactId&gt;org.eclipse.persistence.jpa&lt;/artifactId&gt;
    &lt;version&gt;2.7.3&lt;/version&gt;
    &lt;/dependency&gt;
    

This will result in only 1 remaining jar file which defines javax.persistence.PersistenceContext which is:

  • javax.persistence-api-2.2.jar which is transiently referenced by hibernate-core-5.4.19.jar, the Hibernate ORM provider.

With these changes you can clean up your class path and resolve the runtime error you encountered.

huangapple
  • 本文由 发表于 2020年8月11日 19:18:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63357079.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定