wildfly 10: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

前端 未结 14 948
醉酒成梦
醉酒成梦 2020-11-29 04:25

I have a maven application that works fine in wildfly 8.2, but when Ideployed it in wildfly 10 this error happened:

[2016-02-21 11:22:08,411] Artifact Sarama         


        
相关标签:
14条回答
  • 2020-11-29 04:53

    I just made all hibernate dependencies provided scope and problem solved!

            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>5.1.0.Final</version>
                <scope>provided</scope>
            </dependency>
    
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
                <version>5.2.4.Final</version>
                <scope>provided</scope>
            </dependency>
    
            <!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>5.1.0.Final</version>
                <scope>provided</scope>
            </dependency>
    
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-ehcache</artifactId>
                <version>5.1.0.Final</version>
                <scope>provided</scope>
            </dependency>
    
    0 讨论(0)
  • 2020-11-29 04:56

    If you are using hibernate-core as a dependency, you should make sure the scope is provided. The hibernate artifact has a version of dom4j as a dependency, by making changing the <scope> to provided resolves the conflict.

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.1.Final</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>
    

    I hope this makes you smile :)

    0 讨论(0)
  • 2020-11-29 04:56

    I had the same problem but finally what I did is to remove (redundant) Hibernate libraries from pom.

    As Wildfly is already using Hibernate as JPA provider (https://docs.jboss.org/author/display/WFLY10/JPA+Reference+Guide#JPAReferenceGuide-Introduction), you do not need to provide such classes at all (unless you are directly using Hibernate classes).

    So the minimal config is working fine:

    <project>
      <dependencies>
        <dependency>
          <groupId>javax</groupId>
          <artifactId>javaee-api</artifactId>
          <version>7.0</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>
    </project>
    

    And persistence.xml

    <persistence 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"
             version="2.0">
    <persistence-unit name="mysql_hbm" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>java:/jdbc/MySqlDS</jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
            <property name="hibernate.show_sql" value="true"/>
        </properties>
    </persistence-unit>
    

    Tested on Wildfly 10.

    0 讨论(0)
  • 2020-11-29 04:58

    There are two ways.

    1 You create a META-INF folder in webapp folder. Later create jboss-deployment-structure.xml in META-INF folder.

    jboss-deployment-structure.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
        <deployment>
            <dependencies>
                <module name="org.dom4j"/>
            </dependencies>
        </deployment>
    </jboss-deployment-structure>
    

    or

    2 if you added hibernate-core in pom xml then you edit this.

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.1.Final</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>
    
    0 讨论(0)
  • 2020-11-29 04:59

    adding below in 'jboss-deployment-structure.xml' under META-INF of my ear file resolved the issue and working in both weblogic & wildfly

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
        <deployment>
            <dependencies>
                <module name="org.dom4j" export="true"/>
            </dependencies>
        </deployment>
    </jboss-deployment-structure>
    
    0 讨论(0)
  • 2020-11-29 05:00

    Exclude dependency dom4j out of hibernate ones.

    Check in resulting acme.war/WEB-INF/lib that there is no dom***.jar

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.8.Final</version>
        <exclusions>
            <exclusion>
                <groupId>dom4j</groupId>
                <artifactId>dom4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.8.Final</version>
        <exclusions>
            <exclusion>
                <groupId>dom4j</groupId>
                <artifactId>dom4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
    0 讨论(0)
提交回复
热议问题