2013-06-28 37 views
15

我不能让过去的这个问题。浏览了很多论坛。请帮助:提供了javax.xml.parsers.DocumentBuilderFactory中无法找到

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is javax.xml.parsers.FactoryConfigurationError: Provider for javax.xml.parsers.DocumentBuilderFactory cannot be found.

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

Lib

+0

[可能重复](http://stackoverflow.com/questions/15526419/unexpected-exception-parsing-xml-document-from-servletcontext-resource-web-inf) – gks

+0

我不确定,但看起来像实施DocumentFactoryBuilder的是没有发现即使添加了JAR文件后 – Saket

+0

然后用不同的罐子尝试从[这里](http://www.findjar.com/class/javax/xml/parsers/DocumentBuilderFactory.html)[用法](HTTP: //grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/javax/xml/parsers/DocumentBuilderFactory.java)[更多信息](HTTP://www.developerfusion。com/code/2064/a-simple-way-to-read -a-xml-file-in-java /) – gks

回答

0

我能够找到一个解决方案(通过一些论坛浏览):

  1. 转到位置在您的JRE是当下。 例如,由于我使用的是Websphere Portal JRE,因此我去了以下位置:C:\ Program Files \ IBM5 \ WebSphere \ AppServer \ java \ jre \ lib

  2. 打开jaxb.properties文件并修改属性javax.xml.parsers.DocumentBuilderFactory适用于您的xml解析器。在我的情况是: javax.xml.parsers.DocumentBuilderFactory中= org.apache.xerces.jaxp.DocumentBuilderFactoryImpl

我已晋升到下一个问题:)。我现在正在得到一个ClassCastException。以下是日志:

从ServletContext的资源出现异常的解析XML文档[/WEB-INF/applicationContext.xml的]。嵌套的例外是java.lang.ClassCastException:org.apache.xerces.jaxp.DocumentBuilderFactoryImpl

所有帮助是值得欢迎的。谢谢

+1

这可能有所帮助。 https://community.jboss.org/thread/152151尝试从构建中删除xml-apis.jar。 – austin

11

我们有这个问题也时升级春季和JPA/Hibernate来4.对于我们来说,这是因为Hibernate-EntityManager的4.3.11对依赖于xml-apis的jdom具有依赖性,这将与JRE的rt.jar的javax.xml内容发生冲突。我们排除它,以便我们的spring 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一样)后,它工作正常。

相关问题