尽管调用了方法,为什么 AbstractMvcEndpoint return 的子类还是 404?
Why does a subclass of AbstractMvcEndpoint return a 404 despite the method being called?
在我的端点方法中放置一个断点,我看到它被调用并且 returns 没有任何错误。但是当它到达浏览器时,它说这是一个 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";
}
}
可能是什么原因造成的?
在方法getSomething(...)
中有return "hello";
因此,它将return一个普通视图(网页视图)。
因为你想要return JSON对象,下面方法的结果
@GetMapping( value = "/testendpoint", produces = MediaType.APPLICATION_JSON_UTF8_VALUE )
public String getSomething(HttpServletRequest request) throws Exception
{
return "hello";
}
应该是一个JSON对象.
为了测试 REST 端点,应该使用命令 curl
(在 Linux 上)。如果您使用网络浏览器,您可以使用JSON标记插件(例如:JSONView)。
您可以做一些类似 this with sample source code 的事情。
在我的端点方法中放置一个断点,我看到它被调用并且 returns 没有任何错误。但是当它到达浏览器时,它说这是一个 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";
}
}
可能是什么原因造成的?
在方法getSomething(...)
中有return "hello";
因此,它将return一个普通视图(网页视图)。
因为你想要return JSON对象,下面方法的结果
@GetMapping( value = "/testendpoint", produces = MediaType.APPLICATION_JSON_UTF8_VALUE )
public String getSomething(HttpServletRequest request) throws Exception
{
return "hello";
}
应该是一个JSON对象.
为了测试 REST 端点,应该使用命令 curl
(在 Linux 上)。如果您使用网络浏览器,您可以使用JSON标记插件(例如:JSONView)。
您可以做一些类似 this with sample source code 的事情。