2012-07-12 156 views
0

我想調用一個spring web服務,在瀏覽器中使用下面的url服務「myservice」應該返回XML,即基於@RequestMapping註解是下面的URL是否正確?調用spring web服務

> http://localhost:8080/mywebapp/myservice/feeds/allFeeds.xml/ 


import org.springframework.http.MediaType; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.ResponseBody; 

@Controller 
@RequestMapping("myservice") 
public class TheController { 

    private TheService TheServiceWS; 

    public TheController(TheService TheServiceWS) { 
     this.TheServiceWS = TheServiceWS; 
    } 

    @RequestMapping(value = "feeds/allFeeds.xml", produces = MediaType.APPLICATION_XML_VALUE) 
    @ResponseBody 
    public String getValues() { 
     return TheServiceWS.getAllFeeds(); 
    } 

} 
+0

這取決於您在何處部署應用程序。此外,只是猜測,嘗試'allFeeds.xml'而不是'allFeeds.xml /' – agibalov 2012-07-12 14:51:15

+0

您的web.xml如何配置? – 2012-07-12 14:52:35

回答

0

,我的問題是:

的@RequestMapping註解值 「爲MyService」 是不正確的

應該是 「爲MyWebService」

0

如果Web服務回報XML,它是最初的SOAP Web服務。在這種情況下,您無法使用@RequestMapping構建Web服務。當您想要構建REST Web服務時使用@RequestMapping。

在這種情況下,你應該使用Spring WS。您必須使用@Endpoint註釋該類來創建Web服務端點。在此端點中,您使用@Payloadroot創建了您的請求映射。請參閱this