gpt4 book ai didi

java - XPathFactoryImpl 未找到错误(使用 myBatis)

转载 作者:搜寻专家 更新时间:2023-11-01 01:49:55 24 4
gpt4 key购买 nike

使用 myBatis standAlone(Atlassian jira 插件(OSGi)环境)

发生以下错误。

[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应用环境下不会出现此错误。

我想知道为什么会出现这个错误。

请帮帮我。

谢谢。

最佳答案

我遇到了类似的错误和这个看起来很尴尬的东西,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

关于java - XPathFactoryImpl 未找到错误(使用 myBatis),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40955003/

24 4 0
文章推荐: java - 按空格分隔字符串
文章推荐: javascript - 复制 jQuery 日期选择器
文章推荐: asp.net - javascript 添加到