找不到 javax.xml.parsers.DocumentBuilderFactory 的提供程序

2022-09-02 21:52:26

我无法克服这个问题。浏览了许多论坛。请帮忙:

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml];嵌套的异常是 javax.xml.parsers.FactoryConfigurationError: Provider for javax.xml.parsers.DocumentBuilderFactory 找不到。

我已经将所有jar文件都包含在xerces bin中。以下是我的 WEB-INF/lib 结构:

Lib


答案 1

当将 spring 和 jpa/hibernate 从 3 升级到 4 时,我们也有这个问题。对我们来说,这是因为hibernate-entitymanager 4.3.11依赖于jdom,而jdom依赖于xml-apis,这将与JRE的rt.jar的javax.xml的东西相冲突。我们排除它,以便可以正确解析我们的弹簧xml配置。为了解决这个问题,我们可以从依赖关系树中排除xml-apis。

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <exclusions>
        <exclusion>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
        </exclusion>
    </exclusions>
</dependency>

答案 2

我在使用 WebSphere Portal 8 时也遇到了这个问题。我最近使用xalan 2.7.0来访问和分析XML。

<dependency>
    <groupId>xalan</groupId>
    <artifactId>xalan</artifactId>
    <version>2.7.0</version>
    <exclusions>
        <exclusion>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
        </exclusion>
    </exclusions>
</dependency>

在删除了xml-apis之后(就像Leon Li所做的那样),它工作正常。


推荐