java 无法解析 - org.dom4j.DocumentException: org.dom4j.DocumentFactory 无法转换为 org.dom4j.DocumentFactory

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1804285/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 18:03:26  来源:igfitidea点击:

Could not parse - org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

javahibernatetomcat

提问by Roman

I am deploying my application to Tomcat 6.0.20.

我正在将我的应用程序部署到 Tomcat 6.0.20。

Application uses Hibernate as ORM, Spring, and JSF for web-tier.

应用程序使用 Hibernate 作为 Web 层的 ORM、Spring 和 JSF。

I also made simple runner from main() method to test Spring-Hibernate collaboration. And it does work fine and hibernate.cfg.xml is parsed pretty well.

我还从 main() 方法制作了一个简单的 runner 来测试 Spring-Hibernate 的协作。它确实工作正常并且 hibernate.cfg.xml 解析得很好。

I can append some code or full stack trace but I'm not sure that it's necessary because Google says that it's typical problem and it's easy to recognize it from the title. Unfortunately, I couldn't find the solution..

我可以附加一些代码或完整的堆栈跟踪,但我不确定它是否有必要,因为谷歌说这是典型的问题,很容易从标题中识别出来。不幸的是,我找不到解决方案..

So, who knows how to fix this problem?

那么,谁知道如何解决这个问题?

回答by Bozho

Make sure you don't have two different dom4j jars on your classpath.

确保您的类路径上没有两个不同的 dom4j jar。

回答by Jaanus

I solved it by excluding dom4j from hibernate entitymanager.

我通过从休眠实体管理器中排除 dom4j 来解决它。

Also make sure you do mvn cleanbefore.

还要确保你mvn clean之前这样做。

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.1.5.SP1</version>
        <scope>compile</scope>
        <exclusions> 
            <exclusion>
                <groupId>dom4j</groupId>
                <artifactId>dom4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

回答by ibrabeicker

I solved by adding dom4j to my pom.xmland making the scope provided

我通过将 dom4j 添加到我的pom.xml并提供提供的范围来解决

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