org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service. at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:76) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:296) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:241) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:234) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:189) …… at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:644) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:415) at weblogic.work.ExecuteThread.run(ExecuteThread.java:355) Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: java.lang.RuntimeException: Cannot create a secure XMLInputFactory at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:228) at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:163) at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:74) ... 326 more Caused by: java.lang.RuntimeException: Cannot create a secure XMLInputFactory at org.apache.cxf.staxutils.StaxUtils.createXMLInputFactory(StaxUtils.java:323) at org.apache.cxf.staxutils.StaxUtils.getXMLInputFactory(StaxUtils.java:273) at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1782) at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1681) at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:215) ... 328 more |
Tomcat部署没有问题,weblogic部署后调用方法,报如上问题
woodstox-core-asl-4.4.1.jar 与 wstx-asl-3.2.4 冲突了. 删除wstx-asl-3.2.4j.ar
最终原因是因为下面影响的,通过IDEA找到org.apache.cxf.staxutils.StaxUtils类
Caused by: java.lang.RuntimeException: Cannot create a secure XMLInputFactory
at org.apache.cxf.staxutils.StaxUtils.createXMLInputFactory(StaxUtils.java:323)
if (factory == null || !setRestrictionProperties(factory)) { try { factory = createWoodstoxFactory(); } catch (Throwable var3) { ; } if (!setRestrictionProperties(factory)) { if (!allowInsecureParser) { throw new RuntimeException("Cannot create a secure XMLInputFactory"); } LOG.log(Level.WARNING, "INSECURE_PARSER_DETECTED", factory.getClass().getName()); } } |
然后定位到setRestrictionProperties(factory)
private static boolean setRestrictionProperties(XMLInputFactory factory) { return setProperty((XMLInputFactory)factory, "com.ctc.wstx.maxAttributesPerElement", maxAttributeCount) && setProperty((XMLInputFactory)factory, "com.ctc.wstx.maxAttributeSize", maxAttributeSize) && setProperty((XMLInputFactory)factory, "com.ctc.wstx.maxChildrenPerElement", innerElementCountThreshold) && setProperty((XMLInputFactory)factory, "com.ctc.wstx.maxElementCount", maxElementCount) && setProperty((XMLInputFactory)factory, "com.ctc.wstx.maxElementDepth", innerElementLevelThreshold) && setProperty((XMLInputFactory)factory, "com.ctc.wstx.maxCharacters", maxXMLCharacters) && setProperty((XMLInputFactory)factory, "com.ctc.wstx.maxTextLength", maxTextLength); } |
1. IDEA 用Ctrl+N 查找类com.ctc.wstx发现 woodstox-core-asl-4.4.1.jar 与 wstx-asl-3.2.4 都存在这个路径,且包名和类名都相同
2. 通过createWoodstoxFactory方法往下找,找到尽头发现WstxInputFactory类,Idea 查找类发现 woodstox-core-asl-4.4.1.jar 与 wstx-asl-3.2.4.jar都存在这个类。
3. 综上, woodstox-core-asl-4.4.1.jar 与 wstx-asl-3.2.4.jar存在冲突。尝试之后,发现排除wstx-asl-3.2.4.jar依赖后,项目正常运行。