如何在不修改 Tomcat 的 JVM 参数的情况下包含 xmlparserv2

How to include xmlparserv2 without modifying Tomcat's JVM arguments for

我需要在我的 Apache CXF Spring Web 服务应用程序中包含以下 jar。我用行家。我包括以下依赖项:

    <dependency>
        <groupId>manual</groupId>
        <artifactId>xmlparserv2</artifactId>
        <version>11.1.1.6.0</version>
    </dependency>

这是一个 JAR,是 Oracle 公共模块的一部分。我将它安装在本地 Maven 存储库中。当我 运行 我的服务包含这个 JAR 时,我收到以下错误:

org.xml.sax.SAXParseException; lineNumber: 25; columnNumber: 113; <Line 25, Column 113>: XML-24500: (Error) Can not build schema 'http://www.springframework.org/schema/context' located at 'http://www.springframework.org/schema/context/spring-context.xsd'
    oracle.xml.parser.v2.XMLError.flushErrorHandler(XMLError.java:425)
    oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:287)
    oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:376)
    oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:226)
    oracle.xml.jaxp.JXDocumentBuilder.parse(JXDocumentBuilder.java:155)
    org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
    org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
    org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
    org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
    org.apache.cxf.transport.servlet.CXFServlet.createSpringContext(CXFServlet.java:160)
    org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:74)
    org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:71)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    java.lang.Thread.run(Thread.java:722)

oracle.xml.parser.schema.XSDException: Duplicated definition for: 'identifiedType'
    oracle.xml.parser.schema.XSDBuilder.buildSchema(XSDBuilder.java:794)
    oracle.xml.parser.schema.XSDBuilder.build(XSDBuilder.java:489)
    oracle.xml.parser.schema.XSDValidator.processSchemaLocation(XSDValidator.java:999)
    oracle.xml.parser.schema.XSDValidator.startElement(XSDValidator.java:604)
    oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1524)
    oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:409)
    oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:355)
    oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:226)
    oracle.xml.jaxp.JXDocumentBuilder.parse(JXDocumentBuilder.java:155)
    org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
    org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
    org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
    org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
    org.apache.cxf.transport.servlet.CXFServlet.createSpringContext(CXFServlet.java:160)
    org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:74)
    org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:71)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    java.lang.Thread.run(Thread.java:722)

据我了解,这是一个关于 XML 解析器冲突的问题。我读到这可以通过将此参数添加到 JVM 来解决:

-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

事实上,这解决了问题。然而,这对我来说是不可取的,因为它迫使我向 JVM 添加参数,这可能会导致与应用服务器上部署的其他资源发生冲突(例如 Tomcat)。我需要知道是否有办法解决此错误 而无需 向 JVM 添加参数。例如,通过向 Spring 配置文件添加一些内容,或类似的内容。

好的,我明白了。我必须包括这些依赖项。

    <dependency>
        <groupId>xerces</groupId>
        <artifactId>xercesImpl</artifactId>
        <version>2.11.0</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>xalan</groupId>
        <artifactId>xalan</artifactId>
        <version>2.7.1</version>
        <scope>runtime</scope>
    </dependency>

我不得不在运行时强制包含它们。这会强制框架在运行时使用 xercesImpl 而不是 xmlparserv2。我必须包含 xalan 以便生成的 WSDL 可以包含自定义类型,否则,服务可以工作,但生成的 WSDL 有一个没有定义类型的空部分。