2016-12-04 81 views
3

使用MyBatis的獨立(Atlassian的JIRA插件(OSGi的)environmnent)XPathFactoryImpl未找到錯誤(使用的MyBatis)

發生了下列錯誤。

[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 

源代碼

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 { 
    } 
} 

當添加的Xalan,會出現以下錯誤。

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

在純Java應用程序環境中沒有發生此錯誤。

我不知道爲什麼會出現這個錯誤。

請幫幫我。

謝謝。

+0

代碼正在使用servicelocator來查找要使用的實現。顯然,jar不在類路徑中 – MeBigFatGuy

回答

4

我得到了類似的錯誤,這種尷尬找東西,documented here,固定對我來說:

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

我使用在MacOS此Java版本:

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) 

從-Djaxp的標準錯誤.debug = 1幫我找到這個:

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

所以我給了它究竟是什麼它要求一個第二它得到了所有的快樂,這樣的:

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 

我很好奇:URI語法,因爲下面的工作就好了,而不:URI。那麼爲什麼XPath需要這些,而這些其他的不需要?

-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