RESTful 网络服务、Spring-WS 有效负载或 Spring 3 MVC REST 控制器的哪种方式? [英] which way for RESTful webservice, Spring-WS payloads or Spring 3 MVC REST Controllers?

查看:46
本文介绍了RESTful 网络服务、Spring-WS 有效负载或 Spring 3 MVC REST 控制器的哪种方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Spring Webservices 的初学者.我正在尝试使用 spring-ws 2.0 创建契约优先的 Web 服务.我已经完成了 web.xml (MessageDispatcherServlet) 配置、我的合约设计 (XSD)、生成的 JAXB 类和服务实现.我对端点感到困惑.以下哪一项,mvc rest 控制器或端点,在哪种情况下使用是正确的,为什么?提前致谢.

Im beginner for Spring Webservices. Im trying to create contract-first web services using spring-ws 2.0. I have done web.xml (MessageDispatcherServlet) configurations, my contract-design (XSD), generated JAXB classes and service implementations. Im confused in Endpoints. Which one of the following, mvc rest controllers or enpoints, is correct to use in which scenario and why? Thanks in advance.

@Endpoint
public class PersonEndpoint {

    @Autowired
    private PersonServiceImpl personService;

    @PayloadRoot(localPart = "PersonRequest", namespace = Constants.PERSON_NAMESPACE)
    public @ResponsePayload
    PersonResponseType personReadMethod(@RequestPayload PersonReadRequestType requestElement) {
        return personService.isBiometricNeeded(requestElement);
    }
}

@Controller
public class PersonController {

    @Autowired
    private PersonServiceImpl personService;

    @RequestMapping(value = "/person", method = RequestMethod.GET)
    public @ResponseBody
    PersonResponseType personReadMethod(@RequestBody PersonReadRequestType requestElement) {
        return personService.isBiometricNeeded(requestElement);
    }
}

推荐答案

前者用于 Soap 调用,后者用于休息(我假设您也包括 Jackson)

The former is used for Soap calls, the latter for rest (I assume you have also included Jackson)

您在前者中所做的是声明一个端点,该端点将在传入的带有适当命名空间和 localPart 的soap 调用中被调用.在您的情况下 PersonRequest.

What you're doing in the former is declaring an endpoint which will be called upon an incoming soap call with the appropriate namespace and localPart. In your case PersonRequest.

我建议看一下参考指南的第 3 章,它解释了一个简单的例子:http://static.springsource.org/spring-ws/sites/2.0/reference/html/tutorial.html

I would recommend taking a look at chapter 3 of the reference guide which explains a simple example: http://static.springsource.org/spring-ws/sites/2.0/reference/html/tutorial.html

后者仅用于对 url 的休息调用,并将传入参数转换为 PersonReadRequestType 实例.

The latter is just for a rest call to the url and will transform the incoming parameters to an PersonReadRequestType instance.

这篇关于RESTful 网络服务、Spring-WS 有效负载或 Spring 3 MVC REST 控制器的哪种方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆