RESTful Web服务,Spring-WS有效负载或Spring 3 MVC REST控制器的哪种方式?

时间:2013-02-12 07:55:41

标签: spring rest spring-mvc payload

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

@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);
    }
}

1 个答案:

答案 0 :(得分:3)

前者用于肥皂叫,后者用于休息(我假设你也包括杰克逊)

您在前者中所做的是声明一个端点,该端点将在具有相应命名空间和localPart的传入soap调用时调用。在你的情况下PersonRequest。

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

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

相关问题