2013-02-12 45 views
3

Im初學者爲Spring Webservices。我正在嘗試使用spring-ws 2.0來創建合同優先的Web服務。我完成了web.xml(MessageDispatcherServlet)配置,我的合同設計(XSD),生成了JAXB類和服務實現。我困惑在終點。下列哪一個mvc休息控制器或設定值在哪種情況下使用是正確的,爲什麼?提前致謝。REST風格的webservice,Spring-WS有效載荷或Spring 3 MVC REST控制器的哪種方式?

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

回答

2

前者用於SOAP調用,後者休息(我假設你已經還包括傑克遜)

你在前者做什麼聲明一個端點將被調用一個帶有適當名稱空間和localPart的傳入soap調用。在你的情況PersonRequest。

我建議考慮看看的參考指南,介紹了一個簡單的例子,第3章:http://static.springsource.org/spring-ws/sites/2.0/reference/html/tutorial.html

後者僅僅是一個REST調用的URL,並變換傳入的參數到PersonReadRequestType實例。

+0

謝謝!有所不同。我只需要REST webservices,所以現在使用** DispatcherServlet **而不是** MessageDispatcherServlet **。 – Sridhar 2013-02-13 10:21:27

+0

@Sridhar標記爲已回答 – 2013-02-14 08:32:30