簡體   English   中英

盡管調用了方法,為什么AbstractMvcEndpoint的子類仍返回404?

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

在我的終結點方法中放置一個斷點,我看到它被調用並且它返回而沒有任何錯誤。 但是當它到達瀏覽器時,它說這是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"; 因此,它將返回普通視圖( Web頁面視圖 )。

因為要返回JSON對象,所以下面方法的結果

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

應該是JSON對象

為了測試REST端點,應該使用命令curl (在Linux上)。 如果使用Web瀏覽器,則可以使用JSON標記插件(例如: JSONView )。

你可以做一些喜歡與樣本源代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM