简体   繁体   English

尽管调用了方法,为什么AbstractMvcEndpoint的子类仍返回404?

[英]Why does a subclass of AbstractMvcEndpoint return a 404 despite the method being called?

Putting a breakpoint inside my endpoint method, i see it is called and it returns without any error. 在我的终结点方法中放置一个断点,我看到它被调用并且它返回而没有任何错误。 But when it reaches the browser, it says it was a 404 error. 但是当它到达浏览器时,它说这是404错误。

@Configuration
@ManagementContextConfiguration
@CacheController
public class TestController extends AbstractMvcEndpoint
{
    public TestController()
    {
        super( "/testendpoint", false, true );
    }

    @GetMapping( value = "/testendpoint", produces = MediaType.APPLICATION_JSON_UTF8_VALUE )
    public String getSomething(HttpServletRequest request) throws Exception
    {
        return "hello";
    }
}

What could be causing this? 是什么原因造成的?

In method getSomething(...) has return "hello"; 在方法getSomething(...)return "hello"; Therefore, it will return a normal view ( Web page view ). 因此,它将返回普通视图( Web页面视图 )。

Because you want return JSON object, the outcome of the below method 因为要返回JSON对象,所以下面方法的结果

@GetMapping( value = "/testendpoint", produces = MediaType.APPLICATION_JSON_UTF8_VALUE )
public String getSomething(HttpServletRequest request) throws Exception
{
    return "hello";
}

should be a JSON object . 应该是JSON对象

For testing REST end-point, it should be use command curl (on Linux). 为了测试REST端点,应该使用命令curl (在Linux上)。 If you use web browser, you can use JSON mark-up plug-in (For example: JSONView ). 如果使用Web浏览器,则可以使用JSON标记插件(例如: JSONView )。

You can do something likes this with sample source code . 你可以做一些喜欢与样本源代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM