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

会有一股神秘感。 提交于 2019-11-27 01:16:35

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>

add dependency dom4j to pom with scope provided

<dependency>
   <groupId>dom4j</groupId>
   <artifactId>dom4j</artifactId>
   <version>1.6.1</version>
   <scope>provided</scope>
</dependency>

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 :)

Alvaro Pedraza

I had recently the same problem with the dom4j library and Wildfly 10. I found this post (in portuguese) and replaced the dom4j library that comes with Wildfly with the one downloaded from the Maven Central, and that solved the problem.

The jar is located in $JBOSS_HOME/modules/system/layers/base/org/dom4j/main, you just replace it with the downloaded file, in my case the file was dom4j-1.6.1.jar. I suppose that if you change the version (at the time of this post this is the last version) you should also modify the module.xml file in the same folder, but I've not tried.

Previously I also tried the self-answer from h.f but didn't solved my problem.

Hope this contributes to someone with the same problem. Best regards

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.

The other suggestions here either did not work for me or did not apply to my project. I found a possible solution in this blog. Basically it says to add Dependencies: org.dom4j export to {your war}/META-INF/MANIFEST.MF. I'm running Wildfly 10 and doing so in both my ear and ejb project seems to have worked.

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

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>

Had the same problem, but I solved it using the hibernate5 official quick start available here https://github.com/wildfly/quickstart/tree/11.x/hibernate5

Try the hibernate5 quick start, it should work.

Have a look at the pom.xml, it contains

<!-- Import the JPA API, we use provided scope as the API is included in WildFly -->
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Bean Validation Implementation -->
    <!-- Provides portable constraints such as @Email -->
    <!-- Hibernate Validator is shipped in WildFly -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!--Import dependencies to hibernate packages(eg. hibernate-core)
        depending on features you want to use like Hibernate Session used in the
        quickstart -->
    <!--please note that scope is provided as these jars are shipped
        with as7 -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <scope>provided</scope>
    </dependency>

Include that and it will work. I had to undeploy my app and restart wildfly.

If you need to use another Hibernate version than the one provided in Wildfly, follow the official procedure to update the Hibernate version in Wildly, section Replacing the current Hibernate 5.x jars with a newer version.

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>

In my case helped remove files from /data and /tmp

I am working with Eclipse Neon.3 (4.6.3) and Wildfly 10.1.0.

What worked for me, was to restore an older standalone.xml file from the <wildfly>\standalone\configuration\standalone_xml_history directory. I shut down the server and then replaced the current configuration file with an older backup.

I have no idea what changed in the configuration (I did not alter it manually), but it seems like the error message can be caused by changes in standalone.xml as well.

Maybe this information is helpful, in case none of the other solutions works for you.

Your EAR may contain the duplicate spring jpa configuration file, check and remove the duplicate file

I had the same problem. I followed this instruction and it worked. http://blog.triona.de/development/java/org-dom4j-documentfactory-classcastexception-on-hudson.html

According to this post https://issues.jboss.org/browse/WFLY-5549 we need to create a file named boss-deployment-structure.xml with the content

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

Then place it into ../wildfly/modules/system/layers/base/org/jboss/as/product/wildfly-full/dir/META-INF

I hope this would help.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!