轉:Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found
在用main函式讀取spring配置檔案的時候報錯
provider org.apache.xerces.jaxp.documentbuilderfactoryimpl not found <br>caused by: javax.xml.parsers.factoryconfigurationerror: provider org.apache.xerces.jaxp.documentbuilderfactoryimpl not found <br>at javax.xml.parsers.documentbuilderfactory.newinstance(unknown source) <br>at org.springframework.beans.factory.xml.defaultdocumentloader.createdocumentbuilderfactory(defaultdocumentloader.java:87)
<span style="color: #000000;"><span style="color: blue;"><span style="color: #000000;">解決方法 設定兩個屬性(javax.xml.parsers.documentbuilderfactory,javax.xml.parsers.saxparserfactory)值如下:</span></span> <br></span>
- 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構建路徑-->庫) <br>使得sun.boot.class.path增加了myelipse下的jar檔案,然後就把javax.xml.parsers.documentbuilderfactory變數的值設為org.apache.xerces.jaxp.documentbuilderfactoryimpl <br>即還有第二種解決方法,就是去掉j2ee 1.4 library container庫,編譯,再執行就沒有錯了. <br><br>(jdk版本為1.5與6.0都測試通過). <br>