spring rest項目提示Request method 'PUT' not supported Method Not Allowed 405 錯誤


{
  "timestamp": "2019-04-28 17:43:07",
  "status": 405,
  "error": "Method Not Allowed",
  "message": "Request method 'PUT' not supported",
  "path": "/customer"
}

今天項目發布后,發現系統所有的  PUT請求不能用了, 提示如上,

本地測試正常,發布之后就不行了,瞬間很懵逼了

網上搜了一籮筐信息,發現好像都不對....

仔細看了一下代碼,發現了問題

新版本增加了角色驗證,角色不符合,跳轉到403錯誤頁

我的shiro配置:

       shiroFilterFactoryBean.setFilters(map);
        shiroFilterFactoryBean.setLoginUrl("/login");
        shiroFilterFactoryBean.setSuccessUrl("/index");
        shiroFilterFactoryBean.setUnauthorizedUrl("/home/error/403");
        LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
           filterChainDefinitionMap.put("/customer/login/**","anon");
        filterChainDefinitionMap.put("/upload/**","anon");
        filterChainDefinitionMap.put("/logback/**","anon");

  我的錯誤頁這是這樣的:

    @ApiOperation(value = "角色無權限", notes = "這是一個錯誤處理接口,不需要調試")
    @ApiIgnore
    @RequestMapping(value = "/error/403",method = RequestMethod.GET)
    public Result error403() {
        response.setStatus(403);
        return new Result("角色無權限", false);
    }

啊........... 原來是這樣 

發布后的登陸角色沒有權限,所以跳轉到403頁面  403頁面只支持GET 所以報錯..呵呵 

解決方法:  將403的頁面  method去掉 不限制請求方式.如下

    @ApiOperation(value = "角色無權限", notes = "這是一個錯誤處理接口,不需要調試")
    @ApiIgnore
    @RequestMapping(value = "/error/403")
    public Result error403() {
        response.setStatus(403);
        return new Result("角色無權限", false);
    }

  

順便說一下405錯誤碼  :

405 errors often arise with the POST method. You may be trying to introduce some kind of input form on the Web site, but not all ISPs allow the POST method necessary to process the form.

All 405 errors can be traced to configuration of the Web server and security governing access to the content of the Web site, so should easily be explained by your ISP.

摘自

https://www.checkupdown.com/status/E405.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM