我是 Spring Webservices
的初学者。我正在尝试使用 spring-ws 2.0 创建契约优先的 Web 服务。我已经完成了 web.xml (MessageDispatcherServlet) 配置、契约设计 (XSD)、生成的 JAXB 类和服务实现。我对端点感到困惑。以下哪一项(mvc Rest Controller 或 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);
}
}
最佳答案
前者用于 Soap 调用,后者用于休息(我假设您还包括 Jackson)
您在前者中所做的是声明一个端点,该端点将在传入的肥皂调用时使用适当的命名空间和 localPart 进行调用。在你的情况下 PersonRequest.
我建议您查看引用指南的第 3 章,其中解释了一个简单的示例:http://static.springsource.org/spring-ws/sites/2.0/reference/html/tutorial.html
后者仅用于对 url 的休息调用,并将传入参数转换为 PersonReadRequestType 实例。
关于spring - RESTful Web 服务、Spring-WS 有效负载或 Spring 3 MVC REST Controller 采用哪种方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14827895/