Reputation: 1697
I am trying to implement a Rest Api,the code seems correct and simple but i am getting this error and I can't figure out the problem.
The Log is outputting the following.
2017-10-10 14:49:40.946 WARN 5750 --- [nio-8080-exec-4] o.s.web.servlet.PageNotFound : Request method 'GET' not supported
@RestController("/report")
@CrossOrigin(origins = { "http://localhost:4200" })
public class JasperController {
@RequestMapping(value = "/allReports", method = { RequestMethod.GET }, produces = "application/json")
public String allReport() {
return "allReports!!!";
}
@RequestMapping(value = "/supportedFields", method = { RequestMethod.GET }, produces = "application/json")
public List<String> supportedFields() {
return Arrays.asList("name", "age", "address", "code", "contract");
}
}
Upvotes: 2
Views: 3650
Reputation: 8641
It's pretty simple. The value of @RestController
is not the mapping for it. It's the mistake I've made a lot.
If you want a top-level mapping for all the methods in your controller, declare it with @RequestMapping
on top of your controller class.
@RestController
@RequestMapping("/report")
public class JasperController {
Here is what the value
on @RestController
and @Controller
is:
The value may indicate a suggestion for a logical component name, to be turned into a Spring bean in case of an autodetected component.
Upvotes: 5