How to configure Spring-WS to use JAXB Marshaller?

淺唱寂寞╮ 提交于 2019-12-03 14:04:13
Biju Kunjummen

I would recommend doing it this way, which is a little more standard based on the latest Spring-WS:

Use the oxm namespace to define your marhsaller:

<oxm:jaxb2-marshaller id="marshaller" >
    <oxm:class-to-be-bound name="...Your XMlRootElements.."/>
    <oxm:class-to-be-bound name="more.."/>  
</oxm:jaxb2-marshaller>

Or specify the contextPath:

<oxm:jaxb2-marshaller id="marshaller" contextPath="au.test.weather.ws"/>

Remove reference to GenericMarshallingMethodEndpointAdapter and PayloadRootAnnotationMethodEndpointMapping, replace both instead with sws namespace:

<sws:annotation-driven  />

OR explicitly specify the marshaller/unmarshaller:

<sws:annotation-driven marshaller="marshaller" unmarshaller="marshaller"/>

With these if you endpoint is defined with @EndPoint annotaion, along these lines:

@Endpoint
public class MyEndPoint{

    @PayloadRoot(namespace = "myns", localPart = "rootelement")
    @ResponsePayload
    public MyResponse myMethod(@RequestPayload MyRequest request)

It should just work. Also if your MyRequest class has a @XmlRootElement annotation you don't even need to specify the marshaller, it will be resolved automatically using a built in MethodArgumentResolver.

Reference: http://static.springsource.org/spring-ws/sites/2.0/reference/html/server.html#server-endpoints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!