Wildfly 8.0.0 的类加载问题 [英] classloading problems with Wildfly 8.0.0

查看:26
本文介绍了Wildfly 8.0.0 的类加载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Wildfly 上部署 Spring-JPA-Hibernate Web 应用程序.首先,我在使用 Hibernate 时遇到了问题,这似乎随着

I am trying to deploy a Spring-JPA-Hibernate web application on Wildfly. First, I had problems with Hibernate which seemed to go away with

<jboss-deployment-structure>
  <deployment>
    <exclusions>
      <module name="org.hibernate" slot="main" />
    </exclusions>
    <dependencies>
      <module name="org.hibernate" />
    </dependencies>
  </deployment>
</jboss-deployment-structure>

然而,我的 org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean 试图解析它的 mappingResources(xml 文件),我得到了异常

then however, my org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean tried to parse its mappingResources (xml file), and I got the exception

解析时出错(....等)

org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1163)
    ... 44 more
Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

这似乎表明类路径上还有另一个 dom4j.

which seems to suggest there is another dom4j on the classpath.

此时我迷路了,因为再次修改 jboss-deployment-structure.xml 只会使服务器在启动后很快冻结而没有错误消息.

At this point I got lost, since tinkering again with jboss-deployment-structure.xml only made the server freeze with no error message soon after startup.

有没有一种简单的方法可以告诉 Wildfly 至少不要把它的 dom4j 放在类路径上(或者更好,不要自动添加任何东西)?

Is there a simple way just to tell Wildfly not to put on the classpath at least its dom4j (or better, not to add anything at all automatically)?

推荐答案

我认为您必须选择一种策略来使用 Wildfly 中的类或使用您在应用程序中提供的类.

I think that you must choose a strategy to use the classes from Wildfly or to use the classes you provide in your application.

我在 Wildfly 8.2 中部署的 Liferay 6.2 GA3 也有类似的问题.我使用类似于以下内容的部署描述符解决了它:

I have the similar issue with Liferay 6.2 GA3 deployed in Wildfly 8.2. I solved it using a deployment descriptor similar to:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
   <deployment>
      <exclusions>
         <module name="org.apache.log4j"/>
         <module name="org.hibernate"/>
         <module name="org.hibernate.validator"/>
         <module name="org.jboss.as.jpa"/>
         <module name="org.javassist"/>
         <module name="javaee.api"/>
      </exclusions>
      <dependencies>
         <!-- add the module and remove the dom4j in your application 
              or exclude the module and add the jar in your application -->
         <module name="org.dom4j"/>
         <module name="javax.mail.api"/>
         <module name="org.apache.xerces"/>
         <module name="org.jboss.modules"/>
      </dependencies>
   </deployment>
</jboss-deployment-structure>

https://www.liferay.com/community/论坛/-/message_boards/view_message/40321431#_19_message_47754919

如果要使用 Wildfly 类并在 Wildfly 容器中部署 JPA 实体,请使用类似的 persitence.xml

If you want to use the Wildfly classes and deploy the JPA entities in Wildfly container, use a similar persitence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="MyApp"  transaction-type="JTA" >
        <!-- Data Source -->
        <jta-data-source>java:jboss/datasources/MyApplicationPool</jta-data-source>

    <!-- Class -->
    <class>entities here </class>

    <!-- Properties -->
    <properties>
        <!-- the persitence unit will be deployed in Wildfly and linked to spring 
            using JNDI https://docs.jboss.org/author/display/WFLY8/JPA+Reference+Guide#JPAReferenceGuide-BindingEntityManagerFactory%2FEntityManagertoJNDI -->
        <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/WildflyEntityManagerFactory" />
        <property name="jboss.entity.manager.jndi.name" value="java:/WildflyEntityManagerVMS" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
        <!-- for the JODA datetime -->
        <property name="jadira.usertype.autoRegisterUserTypes" value="true" />
    </properties>
</persistence-unit>

在您的 Spring 应用程序中引用 Wildfly 持久性单元:

Make reference to the Wildfly persitence unit in your Spring application:

<bean id="transactionManager"
    class="org.springframework.transaction.jta.JtaTransactionManager">
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />
<jee:jndi-lookup id="entityManagerFactory"
    jndi-name="java:jboss/WildflyEntityManagerFactory" expected-type="javax.persistence.EntityManagerFactory" />

而且您不应该需要任何特定的 jboss-deployment-structure.

And you should not need any specific jboss-deployment-structure.

这篇关于Wildfly 8.0.0 的类加载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆