Spring rest controller returns 404

烂漫一生 提交于 2021-02-10 22:53:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!