【问题标题】:javax.xml.parsers.DocumentBuilderFactory could not be instantiated in Websphere Application Server with Hibernate 5.2.2 Upgradejavax.xml.parsers.DocumentBuilderFactory 无法通过 Hibernate 5.2.2 升级在 Websphere Application Server 中实例化
【发布时间】:2019-01-09 09:09:09
【问题描述】:

将 Hibernate 4.2 升级到 Hibernate 5.2 版本

在 Websphere 8.5.5.13 版本中部署应用程序时,抛出以下错误

00000001 ContainerHelp E WSVR0501E: 创建组件时出错 com.ibm.ws.runtime.component.CompositionUnitMgrImpl@b9dc2b3a com.ibm.ws.exception.RuntimeWarning: com.ibm.ws.exception.RuntimeError:com.ibm.ws.exception.RuntimeError: java.lang.RuntimeException: javax.xml.parsers.FactoryConfigurationError:提供者 javax.xml.parsers.DocumentBuilderFactory 无法实例化: java.util.ServiceConfigurationError: javax.xml.parsers.DocumentBuilderFactory:提供者 org.apache.xerces.jaxp.DocumentBuilderFactoryImpl 不是子类型 com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCUList(CompositionUnitMgrImpl.java:1303) 在 com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:275)

我尝试删除 xml-api jar 和 maven 排除

         <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate-core.version}</version>
            <exclusions>
                <exclusion>
                <groupId>xml-apis</groupId>
                <artifactId>xml-apis</artifactId>
                </exclusion>
            </exclusions>
        </dependency> 

但是,Web 应用程序在 Tomcat 9 中成功部署,无需任何更改。

堆栈跟踪:

00000001 ContainerHelp E   WSVR0501E: Error creating component com.ibm.ws.runtime.component.CompositionUnitMgrImpl@b9dc2b3a
com.ibm.ws.exception.RuntimeWarning: com.ibm.ws.exception.RuntimeError: com.ibm.ws.exception.RuntimeError: java.lang.RuntimeException: javax.xml.parsers.FactoryConfigurationError: Provider javax.xml.parsers.DocumentBuilderFactory could not be instantiated: java.util.ServiceConfigurationError: javax.xml.parsers.DocumentBuilderFactory: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not a subtype
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCUList(CompositionUnitMgrImpl.java:1303)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:275)
    at com.ibm.ws.runtime.component.ContainerHelper.startComponents(ContainerHelper.java:540)
    at com.ibm.ws.runtime.component.ContainerImpl.startComponents(ContainerImpl.java:627)
    at com.ibm.ws.runtime.component.ContainerImpl.start(ContainerImpl.java:618)
    at com.ibm.ws.runtime.component.ApplicationServerImpl.start(ApplicationServerImpl.java:252)
    at com.ibm.ws.runtime.component.ContainerHelper.startComponents(ContainerHelper.java:540)
    at com.ibm.ws.runtime.component.ContainerImpl.startComponents(ContainerImpl.java:627)
    at com.ibm.ws.runtime.component.ContainerImpl.start(ContainerImpl.java:618)
    at com.ibm.ws.runtime.component.ServerImpl.start(ServerImpl.java:540)
    at com.ibm.ws.runtime.WsServerImpl.bootServerContainer(WsServerImpl.java:316)
    at com.ibm.ws.runtime.WsServerImpl.start(WsServerImpl.java:229)
    at com.ibm.ws.runtime.WsServerImpl.main(WsServerImpl.java:702)
    at com.ibm.ws.runtime.WsServer.main(WsServer.java:59)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke(Method.java:508)
    at com.ibm.wsspi.bootstrap.WSLauncher.launchMain(WSLauncher.java:234)
    at com.ibm.wsspi.bootstrap.WSLauncher.main(WSLauncher.java:96)
    at com.ibm.wsspi.bootstrap.WSLauncher.run(WSLauncher.java:77)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke(Method.java:508)
    at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:587)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:198)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke(Method.java:508)
    at org.eclipse.core.launcher.Main.invokeFramework(Main.java:340)
    at org.eclipse.core.launcher.Main.basicRun(Main.java:282)
    at org.eclipse.core.launcher.Main.run(Main.java:981)
    at com.ibm.wsspi.bootstrap.WSPreLauncher.launchEclipse(WSPreLauncher.java:407)
    at com.ibm.wsspi.bootstrap.WSPreLauncher.main(WSPreLauncher.java:170)
Caused by: com.ibm.ws.exception.RuntimeError: com.ibm.ws.exception.RuntimeError: java.lang.RuntimeException: javax.xml.parsers.FactoryConfigurationError: Provider javax.xml.parsers.DocumentBuilderFactory could not be instantiated: java.util.ServiceConfigurationError: javax.xml.parsers.DocumentBuilderFactory: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not a subtype
    at com.ibm.wsspi.runtime.component.WsComponentImpl.join(WsComponentImpl.java:436)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCUList(CompositionUnitMgrImpl.java:1295)
    ... 39 more
Caused by: com.ibm.ws.exception.RuntimeError: java.lang.RuntimeException: javax.xml.parsers.FactoryConfigurationError: Provider javax.xml.parsers.DocumentBuilderFactory could not be instantiated: java.util.ServiceConfigurationError: javax.xml.parsers.DocumentBuilderFactory: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not a subtype
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:818)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl$5.run(ApplicationMgrImpl.java:2279)
    at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5554)
    at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5680)
    at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2284)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:436)
    at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:379)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access$500(CompositionUnitMgrImpl.java:127)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$CUInitializer.run(CompositionUnitMgrImpl.java:985)
    at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:524)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)
Caused by: java.lang.RuntimeException: javax.xml.parsers.FactoryConfigurationError: Provider javax.xml.parsers.DocumentBuilderFactory could not be instantiated: java.util.ServiceConfigurationError: javax.xml.parsers.DocumentBuilderFactory: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not a subtype
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:1063)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:795)
    ... 12 more
Caused by: javax.xml.parsers.FactoryConfigurationError: Provider javax.xml.parsers.DocumentBuilderFactory could not be instantiated: java.util.ServiceConfigurationError: javax.xml.parsers.DocumentBuilderFactory: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not a subtype
    at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
    at com.ibm.ws.webservices.engine.utils.XMLUtils.getDocumentBuilderFactory(XMLUtils.java:460)
    at com.ibm.ws.webservices.engine.utils.XMLUtils.newDocument(XMLUtils.java:539)
    at com.ibm.ws.webservices.engine.utils.XMLUtils.newDocument(XMLUtils.java:557)
    at com.ibm.ws.webservices.engine.encoding.custom.Utils.loadCustomProviders(Utils.java:267)
    at com.ibm.ws.webservices.tools.resource.ToolEnv$3.run(ToolEnv.java:332)
    at java.security.AccessController.doPrivileged(AccessController.java:638)
    at com.ibm.ws.webservices.tools.resource.ToolEnv.loadCustomProviders(ToolEnv.java:329)
    at com.ibm.ws.webservices.tools.resource.ToolEnv.getCustomBindingProviders(ToolEnv.java:324)
    at com.ibm.ws.webservices.wsdl.toJava.Emitter.initCustomBindingRegistry(Emitter.java:972)
    at com.ibm.ws.webservices.wsdl.toJava.Emitter.setup(Emitter.java:959)
    at com.ibm.ws.webservices.wsdl.Parser.parse(Parser.java:326)
    at com.ibm.ws.webservices.wsdl.Parser.run(Parser.java:313)
    at com.ibm.ws.webservices.tools.WSDLQuery.parse(WSDLQuery.java:142)
    at com.ibm.ws.webservices.engine.deployment.wsdd.WSDDGen.getWSDLQuery(WSDDGen.java:214)
    at com.ibm.ws.webservices.engine.deployment.wsdd.WSDDPort.expand(WSDDPort.java:554)
    at com.ibm.ws.webservices.engine.deployment.wsdd.WSDDPort._initTMR(WSDDPort.java:311)
    at com.ibm.ws.webservices.component.WSServerImpl.setupWsddPort(WSServerImpl.java:1264)
    at com.ibm.ws.webservices.component.WSServerImpl.warMetaDataCreated(WSServerImpl.java:2151)
    at com.ibm.ws.webservices.component.WSServerImpl.metaDataCreated(WSServerImpl.java:639)
    at com.ibm.ws.runtime.component.MetaDataMgrImpl.fireMetaDataCreated(MetaDataMgrImpl.java:279)
    at com.ibm.ws.runtime.component.MetaDataMgrImpl.fireMetaDataCreated(MetaDataMgrImpl.java:262)
    at com.ibm.ws.webcontainer.metadata.WebMetaDataFactory.createMetaData(WebMetaDataFactory.java:244)
    at com.ibm.ws.runtime.component.MetaDataMgrImpl.createMetaDataFromFactories(MetaDataMgrImpl.java:228)
    at com.ibm.ws.runtime.component.MetaDataMgrImpl.createMetaData(MetaDataMgrImpl.java:411)
    at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:631)
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:979)

【问题讨论】:

    标签: hibernate websphere


    【解决方案1】:

    看起来服务器级加载器和“最后一个父级”应用程序类加载器之间存在交叉链接。服务器级(实际上,更可能是 Java 级)加载器加载 DocumentBuilderFactory API 类,然后该类进入线程上下文类加载器以查找其实现。线程上下文类加载器是最后一个父应用加载器,它不会立即委托给它的父应用,因此它会在那里找到实现,然后链接到应用程序的 API 类副本。原始 API 类(来自 Java)和“新”API 类(来自应用程序)不能相互转换,因为它们来自不同的类加载器,操作失败。

    就实际解决这个问题而言:

    1) 有 99.9% 的机会您不需要携带自己的 JAXP 版本,该版本已包含在 JDK 中很长时间(而且您似乎正在打包 Xerces,该版本包含在IBM Java)。删除它将消除该异常。类似地,您可以通过切换到“父级优先”类加载器委托来解决此问题 - 如果您不需要用自己的 API 覆盖服务器 API,它会大大降低出现此类问题的风险。

    2) 话虽如此...您不一定必须删除它,因为服务器通常允许应用程序自带解析器。该异常堆栈意味着某些 WebSphere 代码在创建 XML 对象时可能无法正确保护其线程上下文,您可能希望打开支持票证并让 IBM 验证此处是否存在实际错误。

    【讨论】:

    • 感谢 Jarid 的详细解释。 IBM Websphere 8.5.5.13 不支持 JPA 2.1。但是,Hibernate 5.2.2 版本需要 JPA 2.1 规范。我正在尝试使用隔离的 sharedlib 选项,实习生导致了这个问题。最终我们计划迁移到 WebSphere 9 以支持 JPA 2.1 并避免与 Parent Last Class 加载器策略的 jar 冲突。
    • 了解 JPA 2.1 的事情;但是,您可以从共享库中删除 XML jar,并保留 JPA 内容。服务器的内置 XML 库应该适用于任何级别的 JPA。
    • 好的,Jarid,我会试试这个选项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多