XPathFactoryImpl not found error (using myBatis)
Asked Answered
G

1

7

Using myBatis standAlone (Atlassian jira plugin(OSGi) environmnent)

The following error has occurred.

[INFO] [talledLocalContainer] org.apache.ibatis.exceptions.PersistenceException:
[INFO] [talledLocalContainer]     ### Error building SqlSession.
[INFO] [talledLocalContainer]     ### Cause: java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default o
bject model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: java.
util.ServiceConfigurationError: javax.xml.xpath.XPathFactory: Provider org.apache.xpath.jaxp.XPathFactoryImpl not found
[INFO] [talledLocalContainer] ### Cause: java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException:javax.xml.xpath.XPathFactoryConfigurationException: java.util.ServiceConfigurationError: javax.xml.xpath.XPathFactory: Provider org.apache.xpath.jaxp.XPathFactoryImpl not found

Source Code

static {
    try {
        // set SessionFactory
        if (MyBatisConnectionFactory.sqlSessionFactory == null) {
            MyBatisConnectionFactory.sqlSessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("/mybatisConfig.xml"));
        }

    } catch (final Exception e) {
        MyBatisConnectionFactory.LOGGER.error(e.getMessage());
    } finally {
    }
}

When adding xalan, the following error occurs.

Caused by: java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory

This error did not occur in Pure Java Application environment.

I wonder why this error occurs.

Please help me.

Thanks.

Gnathic answered 4/12, 2016 at 3:18 Comment(1)
code is using servicelocator to find the implementation to use. Apparently that jar isn't on the classpathDannydannye
M
14

I got similar errors and this awkward looking thing, documented here, fixed it for me:

-Djavax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom=com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl

I'm using this java version on macos:

java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

The stderr from -Djaxp.debug=1 helped me find this:

JAXP: Looking up system property 'javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom'
JAXP: The property is undefined.

So I gave it exactly what it was asking for and it got all happy and such:

JAXP: Looking up system property 'javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom'
JAXP: The value is 'com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl'
JAXP: createInstance(com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl)
JAXP: loaded com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl from jar:file:/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Hom     e/jre/lib/rt.jar!/com/sun/org/apache/xpath/internal/jaxp/XPathFactoryImpl.class
JAXP: factory 'com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl' was found for http://java.sun.com/jaxp/xpath/dom

I am curious about the :uri syntax, because the following work just fine without :uri. So why does XPath require this and these others don't?

-Dcom.sun.org.apache.xml.internal.dtm.DTMManager=com.sun.org.apache.xml.internal.dtm.ref.DTMManagerDefault
-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
Maddis answered 29/5, 2017 at 16:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.