spring 工具套件休息服务不引用功能
springtoolsuite rest service not referencing function
我是 java 的新手,正在尝试使用 spring 工具套件实现休息网络服务。我成功地 运行 了一个指南中的示例,并尝试将 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?
我是 java 的新手,正在尝试使用 spring 工具套件实现休息网络服务。我成功地 运行 了一个指南中的示例,并尝试将 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?