spring rest项目提示Request method 'PUT' not supported Method Not Allowed 405 错误

Posted niceletter

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 

以上是关于spring rest项目提示Request method 'PUT' not supported Method Not Allowed 405 错误的主要内容,如果未能解决你的问题,请参考以下文章

在 Spring-data-rest 中使用 Access-Control-Request-Method 发出 OPTIONS 请求时出现 NullPointerException

Spring mvc HandlerInterceptor 怎样获取 rest 参数值

Spring boot 打包为war包报错:提示缺少web.xml

spring security 使用自定义的AuthenticationFilter,提示Invalid remember-me cookie,自动登录失败的解决方法

Extjs 6 + Spring Rest:401 错误的空响应

Django REST:OPTIONS 请求注册为 PUT