作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的端点方法中放置一个断点,我看到它被调用并且返回没有任何错误。但当它到达浏览器时,它说这是一个 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";
因此,它将返回一个普通 View (网页 View )。
因为您想要返回 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 的操作有 sample source code 。
关于java - 尽管调用了该方法,为什么 AbstractMvcEndpoint 的子类仍返回 404?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48456700/
在我的端点方法中放置一个断点,我看到它被调用并且返回没有任何错误。但当它到达浏览器时,它说这是一个 404 错误。 @Configuration @ManagementContextConfigura
在 Spring Boot 1.5.x 中,我通过扩展 AbstractMvcEndpoint 创建了一个执行器端点。但这个类在 Spring Boot 2.x 中不再存在。 我如何升级以下类(cla
我是一名优秀的程序员,十分优秀!