问题
My rest controller ,which is written by spring, returns 404 but when I debug over Eclipse , I see that it comes to my method and returns result but result is still 404.
Controller is like:
@RestController
@RequestMapping("admin/context")
public class ApplicationAdmin {
@Autowired
private ApplicationContextService applicationContextService;
@RequestMapping(value="/monitor",method = RequestMethod.GET, produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public Response monitorContexts(){
return this.applicationContextService.monitorContext();
}
}
There is no exception or error. And the request ur is:
http://localhost:8080/appl_war/admin/context/monitor
回答1:
Try this,
make sure your configuration contains @EnableWebMvc
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"bla.bla.bla"})
public class Configuration{
回答2:
As Danyal Sandeelo says, I think you have to change the RequestMapping
value at class level from "admin/context" to "cmsgateway/admin/context".
来源:https://stackoverflow.com/questions/27983699/spring-rest-controller-returns-404