`

转:Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found

阅读更多

转自:http://lengweiping1983.iteye.com/blog/248563

在用main函数读取spring配置文件的时候报错

 

Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found
Caused by: javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found
at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.createDocumentBuilderFactory(DefaultDocumentLoader.java:87)

解决方法 设置两个属性(javax.xml.parsers.DocumentBuilderFactory,javax.xml.parsers.SAXParserFactory)值如下:

System.setProperty("javax.xml.parsers.DocumentBuilderFactory", 
       "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); 
System.setProperty("javax.xml.parsers.SAXParserFactory", 
       "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"); 

 

最后发现原因是我使用MyEclipse创建项目时引用了J2EE 1.4 Library Container库(JAVA构建路径-->库)
使得sun.boot.class.path增加了myelipse下的jar文件,然后就把javax.xml.parsers.DocumentBuilderFactory变量的值设为org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
即还有第二种解决方法,就是去掉J2EE 1.4 Library Container库,编译,再运行就没有错了.

(JDK版本为1.5与6.0都测试通过).

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics