我是java的新手,并尝试使用spring工具套件实现rest Web服务。我成功地从指南中运行了一个示例,并尝试将POST函数添加到基本的Hello World服务中。 Web服务正在使用Spring启动应用程序运行,我可以追踪的是找不到该功能。 404状态。这是代码:
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
private static final Logger logger = LoggerFactory.getLogger(RestController.class);
@RequestMapping(value = "/greeting", method = RequestMethod.GET)
public @ResponseBody Greeting greeting(@RequestParam(value="name", defaultValue="World") String name, HttpServletResponse httpResponse_p,
WebRequest request_p) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
// @Secured({ "ROLE_USER" })
@RequestMapping(method=RequestMethod.POST, value= {"/addNewPage/{customername}/{streamname}/{name}"})
public Greeting addName(@RequestBody String body, @PathVariable("customername") String customername, @PathVariable("streamname") String streamname,
@PathVariable("name") String name, HttpServletResponse httpResponse_p, WebRequest request_p) {
if (customername.isEmpty() || streamname.isEmpty()) {
String eMessage = "ERROR - NO PARAMETERS INCLUDED!";
httpResponse_p.setStatus(HttpStatus.BAD_REQUEST.value());
return new Greeting (counter.incrementAndGet(), String.format(template, "BAD PARAMETERS"));
}
return new Greeting(counter.incrementAndGet(), String.format("WORKING - ADDED " + name));
}
因此,如果我在浏览器中粘贴以下内容:
http://localhost:8080/greeting?name=Al
我得到以下正确答案:
{"id":2,"content":"Hello, Al!"}
但如果我尝试
http://localhost:8080/addNewPage/something/stream1/ABC
我得到以下内容:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing
this as a fallback.
Tue Mar 24 17:19:29 EDT 2015
There was an unexpected error (type=Not Found, status=404).
No message available
有人能看到我在这里失踪的东西吗?或者如此善意地建议一个好的一步一步的教程,通过以下函数GET / POST / PUT / DELETE?