WebServiceGatewaySupport vs WebServiceTemplate的优点(Advantages of WebServiceGatewaySupport vs WebServi

编程入门 行业动态 更新时间:2024-10-09 13:31:34
WebServiceGatewaySupport vs WebServiceTemplate的优点(Advantages of WebServiceGatewaySupport vs WebServiceTemplate)

我必须使用Spring WS实现一个web服务客户端。

我已阅读http://static.springsource.org/spring-ws/site/reference/html/client.html上的文档,但我不清楚扩展WebServiceGatewaySupport与直接在我的服务中使用WebServiceTemplate的优点类。

据我从源头可以看出, WebServiceGatewaySupport只有一些WebServiceTemplate的封装方法和一些初始化支持。

那么为什么我应该扩展WebServiceGatewaySupport而不是直接使用WebServiceTemplate ?

谢谢!

I have to implement a webservice client using Spring WS.

I've read the documentation at http://static.springsource.org/spring-ws/site/reference/html/client.html but it's not clear to me what are the advantages of extending WebServiceGatewaySupport versus directly using WebServiceTemplate in my service class.

As far as I can tell from the source, the WebServiceGatewaySupport only has a couple of wrapper methods for the WebServiceTemplate and some initialization support.

So why should I extend WebServiceGatewaySupport instead of directly using a WebServiceTemplate ?

Thank you!

最满意答案

我认为这一切总结起来(在您链接的客户端引用中找到):

或者,可以考虑从Spring-WS的WebServiceGatewaySupport方便的基类中派生出来,该基类提供了方便的bean属性来实现简单的配置。 (你不必扩展这个基类......它仅作为一个便利类提供。)

所以,如果WebserviceTemplate提供了所有你需要的,那可能就足够了。 如果您需要额外的任何东西,您可以使用WebServiceGatewaySupport作为示例,了解如何在WebserviceTemplate包装您自己的便捷方法。

在我的客户端软件中,我只需在我的@Configuration类中配置WebserviceTemplate ,如下所示:

@Bean public WebServiceTemplate webServiceTemplate() { WebServiceTemplate template = new WebServiceTemplate(); template.setMessageFactory(messageFactory()); template.setDefaultUri(defaultUri); template.setMarshaller(marshaller()); template.setUnmarshaller(marshaller()); template.setInterceptors(new ClientInterceptor[] {interceptor()}); return template; }

(所有的方法调用都是对配置中其他方法的引用,这些在本例中并不相关)。 我可以在我的代码中的任何地方使用该bean来发送消息。

I think this sums it all up (found in the client reference you linked):

Alternatively, consider deriving from Spring-WS's WebServiceGatewaySupport convenience base class, which exposes convenient bean properties to enable easy configuration. (You do not have to extend this base class... it is provided as a convenience class only.)

So, if the WebserviceTemplate offers all you need, that'll probably suffice. If you need anything extra you can use the WebServiceGatewaySupport as an example on how to wrap your own convenience methods around the WebserviceTemplate.

In my client software, I just configure the WebserviceTemplate in my @Configuration class like this:

@Bean public WebServiceTemplate webServiceTemplate() { WebServiceTemplate template = new WebServiceTemplate(); template.setMessageFactory(messageFactory()); template.setDefaultUri(defaultUri); template.setMarshaller(marshaller()); template.setUnmarshaller(marshaller()); template.setInterceptors(new ClientInterceptor[] {interceptor()}); return template; }

(All the method calls are references to other methods in the configuration which aren't that relevant in this example). I can use that bean everywhere in my code to send messages.

更多推荐

本文发布于:2023-08-04 03:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405405.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:优点   WebServiceGatewaySupport   WebServiceTemplate   Advantages

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!