创建Spring bean时未知属性accessExternalDTD

时间:2019-01-21 10:46:10

标签: java xml spring saxparser

我继承了一个旧的(已使用15年的)Java应用程序,该应用程序维护得很差。 Mavenizing没有正确完成,因此我尝试了一下,因为有很多库是手动添加到类路径中的。现在,我有了一个主pom,该pom文件中的所有库都具有依赖性。

错误如下:

  

调用init方法失败;嵌套的异常是java.lang.IllegalArgumentException:未知属性http://javax.xml.XMLConstants/property/accessExternalDTD

但是现在启动我的Web服务时遇到一些解析器问题。旧项目使用XML的SaxParser,但也使用Spring,在初始化bean时看到冲突。

我已经升级到Java 8(因为我们与IBM JDK 8绑定到IBM,所以也可以在Liberty Profile上运行)。添加了jaxp-api,以在类路径上获取'accessExternalDTD'属性。删除了xerces实现(也从xalan依赖项中排除),但没有任何效果。

[err] JAXP: find factoryId=javax.xml.parsers.DocumentBuilderFactory
[err] JAXP: found service provider by ServiceLoader, value=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
2019-01-21 11:18:35 DEBUG CalculationExecutor:186 -    0.000 CalculationExecutor.new: begin

2019-01-21 11:18:35 DEBUG Loader:50 - Trying to find [project-calculationKernel.xml] using context classloader: com.ibm.ws.classloading.internal.ThreadContextClassLoader@c5d35d81.

2019-01-21 11:18:35 DEBUG Loader:56 - Found: wsjar:file:/C:/LogFiles/Tools/wlp-webProfile8-java8-win-x86_64-18.0.0.4/wlp/usr/servers/Server18.0.0.4/apps/expanded/CreditRiskWebServicesEAR.ear/CreditRiskWebServices.war/WEB-INF/lib/RiskRatingCalculation-17.0.48-SNAPSHOT.jar!/project-calculationKernel.xml

2019-01-21 11:18:35 INFO  BaseCastorMappingMarshaller:33 - Castor version used by Castor Mapping Marshaller: 1.2  [0]

2019-01-21 11:18:35 DEBUG Loader:50 - Trying to find [castorMapping-projectConfiguration.xml] using context classloader: com.ibm.ws.classloading.internal.ThreadContextClassLoader@c5d35d81.

2019-01-21 11:18:35 DEBUG Loader:56 - Found: wsjar:file:/C:/LogFiles/Tools/wlp-webProfile8-java8-win-x86_64-18.0.0.4/wlp/usr/servers/Server18.0.0.4/apps/expanded/CreditRiskWebServicesEAR.ear/CreditRiskWebServices.war/WEB-INF/lib/CalculationKernelSE-17.0.48-SNAPSHOT.jar!/castorMapping-projectConfiguration.xml

[err] JAXP: find factoryId=javax.xml.parsers.SAXParserFactory
[err] JAXP: found service provider by ServiceLoader, value=org.apache.xerces.jaxp.SAXParserFactoryImpl
[err] JAXP: find factoryId=javax.xml.parsers.SAXParserFactory
[err] JAXP: found service provider by ServiceLoader, value=org.apache.xerces.jaxp.SAXParserFactoryImpl
2019-01-21 11:18:35 DEBUG CalculationExecutor:186 -    0.00691 CalculationExecutor.new: end

[err] JAXP: find factoryId=javax.xml.parsers.DocumentBuilderFactory
[err] JAXP: found service provider by ServiceLoader, value=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
[err] JAXP: find factoryId=javax.xml.transform.TransformerFactory
[err] Warning: external object model net.sf.saxon.dom.DOMEnvelope has been loaded, but is not an instance of net.sf.saxon.om.ExternalObjectModel
[err] Warning: external object model net.sf.saxon.dom.DOMObjectModel has been loaded, but is not an instance of net.sf.saxon.om.ExternalObjectModel
[err] JAXP: found service provider by ServiceLoader, value=net.sf.saxon.TransformerFactoryImpl
[ERROR   ] SRVE0283E: Exception caught while initializing context: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'soapRiskApprovalService' defined in ServletContext resource [/WEB-INF/applicationContext-creditRiskWebServices.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Unknown attribute http://javax.xml.XMLConstants/property/accessExternalDTD
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
    at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$136.00000000124ED300.getObject(Unknown Source)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:400)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
    at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2376)
    at [internal classes]
Caused by: java.lang.IllegalArgumentException: Unknown attribute http://javax.xml.XMLConstants/property/accessExternalDTD
    at net.sf.saxon.Configuration.setConfigurationProperty(Configuration.java:2185)
    at net.sf.saxon.TransformerFactoryImpl.setAttribute(TransformerFactoryImpl.java:342)
    at org.springframework.xml.transform.TransformerFactoryUtils.defaultSettings(TransformerFactoryUtils.java:56)
    at org.springframework.xml.transform.TransformerFactoryUtils.newInstance(TransformerFactoryUtils.java:32)
    at org.springframework.xml.transform.TransformerHelper.newTransformerFactory(TransformerHelper.java:88)
    at org.springframework.xml.transform.TransformerHelper.getTransformerFactory(TransformerHelper.java:104)
    at org.springframework.xml.transform.TransformerHelper.createTransformer(TransformerHelper.java:119)
    at org.springframework.xml.transform.TransformerHelper.transform(TransformerHelper.java:131)
    at org.springframework.xml.transform.TransformerObjectSupport.transform(TransformerObjectSupport.java:96)
    at org.springframework.ws.wsdl.wsdl11.provider.InliningXsdSchemaTypesProvider.getSchemaElement(InliningXsdSchemaTypesProvider.java:113)
    at org.springframework.ws.wsdl.wsdl11.provider.InliningXsdSchemaTypesProvider.addTypes(InliningXsdSchemaTypesProvider.java:101)
    at org.springframework.ws.wsdl.wsdl11.ProviderBasedWsdl4jDefinition.afterPropertiesSet(ProviderBasedWsdl4jDefinition.java:234)
    at org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition.afterPropertiesSet(DefaultWsdl11Definition.java:183)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741)
    ... 15 more

我在Google上搜索了很多,但是我找不到能使这个旧应用程序启动的任何方法。希望有人确实遇到了同样的问题,并能为我指出如何处理此问题的方式。

3 个答案:

答案 0 :(得分:1)

您的问题似乎与SWS-1049有关,它是在spring-ws 3.0.6.RELEASE中引入的。您需要改用3.0.7.BUILD-SNAPSHOT。

答案 1 :(得分:0)

尝试从JDK 8中设置 TransformerFactory 。这在JBoss中存在问题,但是代码快照应以相同的方式工作https://stackoverflow.com/a/55304023/204950

答案 2 :(得分:0)

我在使用旧代码时遇到了同样的问题,在该代码中,无法删除SaxonJ或其他依赖项。

我最终跟随TransformerFactory::newInstance docs,添加了一个系统属性来定义要实例化的默认TransformerFactory:

-Djavax.xml.transform.TransformerFactory=com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl

注意:示例正在使用OpenJDK8,您将必须找到所需的TransformerFactoryImpl