我想調用一個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();
}
}
這取決於您在何處部署應用程序。此外,只是猜測,嘗試'allFeeds.xml'而不是'allFeeds.xml /' – agibalov 2012-07-12 14:51:15
您的web.xml如何配置? – 2012-07-12 14:52:35