【问题标题】:Spring rest controller returns 404弹簧休息控制器返回 404
【发布时间】:2017-10-07 23:38:46
【问题描述】:

我的由 spring 编写的 rest 控制器返回 404,但是当我在 Eclipse 上调试时,我看到它来到我的方法并返回结果,但结果仍然是 404。

控制器是这样的:

@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();
    }
}

没有异常或错误。请求是:

http://localhost:8080/appl_war/admin/context/monitor

【问题讨论】:

标签: spring rest


【解决方案1】:

试试这个,

确保您的配置包含 @EnableWebMvc

    @Configuration
    @EnableWebMvc
    @ComponentScan(basePackages = {"bla.bla.bla"})
    public class Configuration{

【讨论】:

    【解决方案2】:

    正如 Danyal Sandeelo 所说,我认为您必须将类级别的 RequestMapping 值从 "admin/context" 更改为 "cmsgateway/admin/context ”。

    【讨论】:

    • 已编辑网址。没有cmsgateway。请求来自我的控制器方法,我可以看到。但它仍然给出 404...
    • 啊!我也错过了!试试这个,“/admin/context”(注意它以 / 开头)
    猜你喜欢
    • 2017-09-01
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    • 1970-01-01
    相关资源
    最近更新 更多