簡體   English   中英

創建 Spring bean 時的未知屬性 accessExternalDTD

[英]Unknown attribute accessExternalDTD while creating Spring bean

我繼承了一個維護很差的舊(15 年)Java 應用程序。 Mavenizing 沒有正確完成,所以我確實試了一下,因為很多庫都是手動添加到類路徑中的。 現在我有一個主 pom,它在 pom 文件中將所有庫作為依賴項。

錯誤如下:

init 方法調用失敗; 嵌套異常是 java.lang.IllegalArgumentException: Unknown attribute http://javax.xml.XMLConstants/property/accessExternalDTD

但是現在我在啟動我的網絡服務時遇到了一些解析器問題。 舊項目對 XML 使用 SaxParser,但它也使用 Spring,我在初始化 bean 時看到沖突。

我已經升級到 Java 8(也在 Liberty Profile 上運行,因為我們使用 IBM JDK 8 綁定到 IBM)。 添加了 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

我用谷歌搜索了很多,但我找不到任何可以啟動這個舊應用程序的方法。 希望有人確實遇到過同樣的問題,並能指出我如何處理這個問題。

您的問題似乎與SWS-1049 有關,它是在 spring-ws 3.0.6.RELEASE 中引入的。 你需要使用 3.0.7.BUILD-SNAPSHOT 代替。

嘗試從 JDK 8 設置TransformerFactory。JBoss 中存在一個問題,但代碼快照應該以相同的方式工作https://stackoverflow.com/a/55304023/204950

我在舊代碼中遇到了同樣的問題,其中刪除 SaxonJ 或其他依賴項不是一種選擇。

我最終通過添加系統屬性來定義要實例化的默認 TransformerFactory 來遵循TransformerFactory::newInstance 文檔

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

注意:示例使用 OpenJDK8,您必須找到所需的TransformerFactoryImpl

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM