【问题标题】:classloading problems with Wildfly 8.0.0Wildfly 8.0.0 的类加载问题
【发布时间】:2015-02-16 17:51:16
【问题描述】:

我正在尝试在 Wildfly 上部署 Spring-JPA-Hibernate Web 应用程序。首先,我在使用 Hibernate 时遇到了问题,而

<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 文件),我得到了异常

Error while parsing(....等)

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。

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

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

【问题讨论】:

    标签: wildfly wildfly-8


    【解决方案1】:

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

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

    <?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/forums/-/message_boards/view_message/40321431#_19_message_47754919

    如果您想使用 Wildfly 类并在 Wildfly 容器中部署 JPA 实体,请使用类似的 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 持久性单元:

    <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。

    【讨论】:

      猜你喜欢
      • 2014-04-02
      • 1970-01-01
      • 2017-05-16
      • 2018-09-26
      • 2017-05-07
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 2014-11-12
      相关资源
      最近更新 更多