2017-10-10 95 views
2

我想實現一個休息Api,代碼似乎正確和簡單,但我得到這個錯誤,我不知道這個問題。 enter image description here春季休息請求方法'GET'不支持

Log正在輸出以下內容。

2017年10月10日14:49:40.946 WARN 5750 --- [NIO-8080-EXEC-4] osweb.servlet.PageNotFound:請求方法 'GET' 不支持

 @RestController("/report") 
    @CrossOrigin(origins = { "http://localhost:4200" }) 
    public class JasperController { 

     @RequestMapping(value = "/allReports", method = { RequestMethod.GET }, produces = "application/json") 
     public String allReport() { 
         return "allReports!!!"; 
        } 

     @RequestMapping(value = "/supportedFields", method = { RequestMethod.GET }, produces = "application/json") 
     public List<String> supportedFields() { 
         return Arrays.asList("name", "age", "address", "code", "contract"); 
     } 

    } 
+0

您允許的出處是「http:// localhost:4200」,並且您從「http:// localhost:8080」調用瀏覽器。端口不匹配,所以你的來源是不允許的 – Leffchik

+0

我刪除了它,同樣的錯誤仍然在增加,我不認爲問題是允許的來源。 –

+0

奇怪.. R確定您的控制器包是實際被Spring掃描的嗎? – Leffchik

回答

2

這很簡單。 @RestController的值不是它的映射。這是我犯了很多錯誤。 如果您想要控制器中所有方法的頂級映射,請在控制器類的頂部使用@RequestMapping進行聲明。

@RestController 
@RequestMapping("/report") 
public class JasperController { 

下面是對@RestController@Controllervalue是:

值可以指示邏輯組件名稱的建議,以 變成一個Spring bean在自動檢測組件的情況下, 。

相關問題