0

我正在尝试调用 Spring Web 服务,在浏览器中使用下面的 url 服务“myservice”应该返回 XML,即基于 @RequestMapping 注释,下面的 URL 是否正确?

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

}
4

2 回答 2

0

我的问题是:

@RequestMapping 注释值“myservice”不正确

应该是“mywebservice”

于 2012-07-12T15:25:28.883 回答
0

如果 Web 服务以 XML 形式返回,则它是原始的 SOAP Web 服务。在这种情况下,您无法使用 @RequestMapping 构建 Web 服务。当您想要构建 REST Web 服务时使用 @RequestMapping。

在这种情况下,您应该使用 Spring WS。您必须使用 @Endpoint 注释该类以创建 Web 服务端点。在此端点中,您使用 @Payloadroot 创建请求映射。请参考这个

于 2016-05-24T16:05:01.233 回答