JBoss AS7 LinkageError for HibernatePersistenceProvider.createEntityManagerFactory()方法

时间:2016-03-17 18:46:15

标签: java spring hibernate jpa jboss

我正在创建一个Spring MVC和Hibernate / JPA Web应用程序,并且我在配置应用程序和jboss-deployment描述符方面遇到了问题,因此我可以将持久性管理委派给我的Web应用程序而不是JBoss AS7。 我正在为JavaEE7,Spring 4.2.2-Final和Hibernate 4.3.11开发。

这是我的jboss-deployment-structure.xml

的内容
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure >
<deployment>
    <exclude-subsystems>
        <subsystem name="jpa"/>
    </exclude-subsystems>
    <exclusions>
        <module name="org.hibernate" />
        <module name="javaee.api" />
        <module name="javax.persistence.api" />
    </exclusions>
    <dependencies>
        <module name="javaee.api">
            <imports>
                <exclude path="javax/persistence" />
            </imports>
        </module>
    </dependencies>
</deployment>
</jboss-deployment-structure>

使用这个我能够通过我最初的AS7问题依赖于它的默认hibernate-jpa-2.0-api.jar并使用我的web应用程序部署的hibernate-jpa-2.1-api.jar。

但是,我现在通过管理控制台启动我的网络应用时出现此错误。

12:56:48,885 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/mis-dashboard]] (ServerService Thread Pool -- 230) JBWEB000289: Servlet appServlet threw load() exception: java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(Ljava/lang/String;Ljava/util/Map;)Ljavax/persistence/EntityManagerFactory;" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the current class, org/hibernate/jpa/HibernatePersistenceProvider, and the class loader (instance of org/jboss/modules/ModuleClassLoader) for interface javax/persistence/spi/PersistenceProvider have different Class objects for the type erFactory(Ljava/lang/String;Ljava/util/Map;)Ljavax/persistence/EntityManagerFactory; used in the signature
at java.lang.Class.getDeclaredConstructors0(Native Method) [rt.jar:1.7.0_45]
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493) [rt.jar:1.7.0_45]
at java.lang.Class.getConstructor0(Class.java:2803) [rt.jar:1.7.0_45]
at java.lang.Class.newInstance(Class.java:345) [rt.jar:1.7.0_45]
at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.<init>(HibernateJpaVendorAdapter.java:93) [spring-orm-4.1.9.RELEASE.jar:4.1.9.RELEASE]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_45]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_45]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_45]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [rt.jar:1.7.0_45]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:299) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1048) [spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:825) [spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) [spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667) [spring-webmvc-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633) [spring-webmvc-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681) [spring-webmvc-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552) [spring-webmvc-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493) [spring-webmvc-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) [spring-webmvc-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1194) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1100) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3591) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3798) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:161) [jboss-as-web-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:59) [jboss-as-web-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:94) [jboss-as-web-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_45]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_45]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)

12:56:48,901 DEBUG [org.apache.jasper.compiler] (ServerService Thread Pool -- 230) JBWEB005025: Parent 

从异常中可以看出,Jboss ModuleClassLoader与javax.persistence.EntityManagerFactory类存在冲突。我认为我的部署描述符中的条目会阻止这一点,但显然情况并非如此。

我是一位经验丰富的软件工程师,具有一定的Application Server管理经验,但老实说,这只是危险的。通常,我会依赖服务器管理员团队,但这里没有这样的团队。

有没有人有这种或类似情况的经验? 关于如何修复此LinkageError并解决冲突的任何想法?

提前谢谢你,

mbeddedsoft

1 个答案:

答案 0 :(得分:1)

我在JBoss EAP 6.4,Spring 4.2.4和Hibernate 4.3.11上遇到了类似的问题。

我使用了以下jboss-deployment-structure.xml,并且能够部署我的Web应用程序:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <exclude-subsystems>
            <subsystem name="jpa" />
        </exclude-subsystems>
        <exclusions>
            <module name="javaee.api" />
            <module name="javax.persistence.api" />
        </exclusions>
        <dependencies>
            <module name="javaee.api">
                <imports>
                    <exclude path="javax/persistence" />
                </imports>
            </module>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

但是,每次重新部署webapp时,我都会遇到类似的LinkageError问题。 在实现此处描述的解决方法2之后,所有工作都可以实现:https://issues.jboss.org/browse/WFCORE-209