gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:42:26 25 4
gpt4 key购买 nike

在我的端点方法中放置一个断点,我看到它被调用并且返回没有任何错误。但当它到达浏览器时,它说这是一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com