Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Provider for javax.xml.parsers.DocumentBuilderFactory cannot be found

Tags:

java

xml

I am not able to get past this problem. Browsed through many forums. Pls help:

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.

I have included all the jar files in xerces bin. Following is my WEB-INF/lib structure:

Lib

like image 848
Saket Avatar asked Jun 28 '13 08:06

Saket


People also ask

What is DocumentBuilderFactory in Java?

public abstract class DocumentBuilderFactory extends Object. Defines a factory API that enables applications to obtain a parser that produces DOM object trees from XML documents.

What is SAXParserFactory Java?

public abstract class SAXParserFactory extends Object. Defines a factory API that enables applications to configure and obtain a SAX based parser to parse XML documents.


3 Answers

We have this problem also when upgrade spring and jpa/hibernate from 3 to 4. For us it is because hibernate-entitymanager 4.3.11 has a dependency on jdom which has a dependency on xml-apis which will conflict with the JRE’s rt.jar’s javax.xml stuff. We exclude it so that our spring xml config could be correctly parsed. To solve the problem, we can just exclude the xml-apis from the dependency tree.

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <exclusions>
        <exclusion>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
        </exclusion>
    </exclusions>
</dependency>
like image 59
LeOn - Han Li Avatar answered Sep 19 '22 14:09

LeOn - Han Li


I also had this problem working with WebSphere Portal 8. I was recently using xalan 2.7.0 for accessing and parsing 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>

After removing the xml-apis (like Leon Li did) it worked fine.

like image 20
MMascarin Avatar answered Sep 19 '22 14:09

MMascarin


I could resolve the above problem entirely, by setting the order in which classloader should load the xerces jar files (WAR->EAR->Server). The following link is taken from Xerces site at Apache. It helps to resolve the above issue for Websphere Portal/WAS:

http://www.ibm.com/developerworks/websphere/library/techarticles/0310_searle/searle.html

like image 33
Saket Avatar answered Sep 20 '22 14:09

Saket