WildFly 14-java.lang.ClassCastException:org.dom4j.DocumentFactory无法转换为org.dom4j.DocumentFactory

时间:2018-10-20 10:49:12

标签: java hibernate java-ee wildfly

我有一个可以在WildFly 8.2.1上运行的应用程序。最终发行版完美无缺。但是我想将服务器版本从8.2.1.Final升级到14.0.1.Final,并在将数据源添加到14.0.1.Final之后,我正在启动应用程序并遇到错误。

  • 我试图将提供的作用域添加到休眠核心依赖中,但没有解决。
  • 我试图将dom4j添加为maven依赖项,但没有解决。
  • 我从WildFly模块中删除了dom4j.jar并添加为maven依赖项,但这一次我遇到了模块加载问题。

该问题的解决方案是什么?

13:32:25,121 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 17) MSC000001: Failed to start service jboss.persistenceunit."warName.war#persistenceUnitName": org.jboss.msc.service.StartException in service jboss.persistenceunit."warName.war#persistenceUnitName": java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:195)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:125)
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:650)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:209)
    at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
    at java.lang.Thread.run(Thread.java:748)
    at org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
    at org.dom4j.DocumentFactory.getInstance(DocumentFactory.java:97)
    at org.hibernate.internal.util.xml.XMLHelper$1.doWork(XMLHelper.java:33)
    at org.hibernate.internal.util.xml.XMLHelper$1.doWork(XMLHelper.java:27)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.workWithClassLoader(ClassLoaderServiceImpl.java:483)
    at org.hibernate.internal.util.xml.XMLHelper.<init>(XMLHelper.java:26)
    at org.hibernate.envers.boot.internal.EnversServiceImpl.initialize(EnversServiceImpl.java:116)
    at org.hibernate.envers.boot.internal.AdditionalJaxbMappingProducerImpl.produceAdditionalMappings(AdditionalJaxbMappingProducerImpl.java:101)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:297)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:904)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935)
    at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:167)
    ... 9 more

13:32:25,133 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 1) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "warName.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"warName.war#persistenceUnitName\"" => "java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
    Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory"}}
13:32:25,135 ERROR [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0021: Deploy of deployment "warName.war" was rolled back with the following failure message: 
{"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"warName.war#persistenceUnitName\"" => "java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
    Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory"}}
13:32:25,155 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 17) WFLYJPA0011: Stopping Persistence Unit (phase 1 of 2) Service 'warName.war#persistenceUnitName'
13:32:25,376 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0028: Stopped deployment authentication.war (runtime-name: warName.war) in 241ms
[2018-10-20 01:32:25,481] Artifact module:war: Error during artifact deployment. See server log for details.
[2018-10-20 01:32:25,482] Artifact module:war: java.lang.Exception: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"warName.war#persistenceUnitName\"" => "java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
    Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory"}}

3 个答案:

答案 0 :(得分:1)

https://issues.jboss.org/browse/WFLY-5549

找到了可能的解决方案

基本添加一个jboss-deployment-structure.xml,它将对模块org.dom4j的依赖添加到一个

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

还要在战争中检查您的lib文件夹。 删除所有与休眠相关的jar。也是dom4j Wildfly已经提供了它们。 在休眠模块modules / system / layers / base / org / hibernate / main / module.xml中设置了对org.dom4j的依赖关系。

答案 1 :(得分:0)

在pom.xml中修改依赖项hibernate-core:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.3.6.Final</version>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>

添加exclusion标签。然后清理并构建。它对我有用。

答案 2 :(得分:0)

在我的情况下,问题是由在standalone.xml中添加了2个驱动程序引起的,其中一个指向ojdbc6,另一个指向ojdbc7(从oracle分发),并在wf14中作为模块公开。 即使我排除了dom4j,或者即使我从pom或jboss-deployment-structure.xml导入,异常仍然存在。

在删除较旧的驱动程序(更新使用它的数据源)并仅保留ojdbc7之后,异常消失了。

希望有帮助。