-->

Spring webservicetemplate jar conflict issue with

2019-08-17 03:58发布

问题:

I use Spring web services and Axis2 both in my app. They are completely independent and it works great, except that Spring WebServiceTemplate started throwing the exception below..

I suspect it's happening because Spring requires saaj.jar (which has javax.xml.soap.SOAPElement) and Axis2 requires axiom-dom.jar (which has org.apache.axiom.om.impl.dom.ElementImpl)

Both the interfaces extend org.w3c.dom.Element and somehow Spring in picking up the one from axiom-dom.jar

Any ideas as to what i can do to prevent Spring from picking up the wrong implementation at runtime other than perhaps renaming axiom-dom.jar to z-axiom-dom.jar, so its later in the classpath?

com.sun.xml.wss.XWSSecurityException: com.sun.xml.wss.XWSSecurityException: java.lang.ClassCastException: org.apache.axiom.om.impl.dom.ElementImpl cannot be cast to javax.xml.soap.SOAPElement at org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor.secureMessage(XwsSecurityInterceptor.java:139) at org.springframework.ws.soap.security.AbstractWsSecurityInterceptor.handleRequest(AbstractWsSecurityInterceptor.java:179) at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:542) at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:502) at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:351) at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:341)

回答1:

This is not a conflict between saaj and axiom-dom, but a conflict between saaj and axis2-saaj.jar. axis2-saaj uses axiom-dom which is why the exception refers to Axiom. If you don't use the JAX-WS implementation provided by Axis2, then you don't need axis2-saaj, so depending on your use case, removing it may be a solution.