添加“ apache cxf-bundle”作为gradle中的依赖项时,出现“不支持:http://javax.xml.XMLConstants/property/accessExternalDTD异常”

时间:2019-05-15 10:52:11

标签: java build.gradle wsdl2java

尝试在我的应用程序中添加apache-cxf软件包。但是在运行该应用程序时出现以下错误     无法实例化  [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping]:工厂方法'payloadRootAnnotationMethodEndpointMapping'抛出异常;嵌套的异常是java.lang.ExceptionInInitializerError

这是由于   原因:java.lang.IllegalArgumentException:不支持:http://javax.xml.XMLConstants/property/accessExternalDTD

试图在任务中添加以下属性

wsdl2java {
 System.setProperty('javax.xml.accessExternalSchema', 'all')
 System.setProperty('javax.xml.accessExternalDTD','all')
 generatedWsdlDir = file("src/main/generated-sources/")  // target directory for generated source code
 wsdlsToGenerate = [   //  2d-array of wsdls and cxf-parameters
                      ['src/main/resources/xsd/wsdl/***.wsdl'],
]

}

added the dependency as 
compile group: 'org.apache.cxf', name: 'cxf-bundle', version: '2.4.2'

出现以下错误

Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping]: Factory method 'payloadRootAnnotationMethodEndpointMapping' threw exception; nested exception is java.lang.ExceptionInInitializerError

Caused by: java.lang.IllegalArgumentException: Not supported: http://javax.xml.XMLConstants/property/accessExternalDTD
    at org.apache.xalan.processor.TransformerFactoryImpl.setAttribute(TransformerFactoryImpl.java:576) ~[xalan-2.7.1.jar:?]

1 个答案:

答案 0 :(得分:1)

在检查依赖关系树时,看到多个版本的Xalan。这会使依赖关系发生冲突。通过添加以下行来解决错误

 compile (group: 'org.apache.cxf', name: 'cxf-bundle', version: '2.4.2')  {    
 exclude module: 'xalan'
}