Springboot使用put、delete请求报错405的处理

2022-07-14,,,,

springboot使用putdelete请求报错

springboot给我们自动配置好了hiddenhttpmethodfilter,但是最近发现好像用不了,我用的是springboot版本是2.2.2,默认配置被改成了false,也就是关闭了自动配置,不知道sprongboot什么鬼,坑!!!

there was an unexpected error (type=method not allowed, status=405).
request method 'post' not supported
org.springframework.web.httprequestmethodnotsupportedexception: request method 'post' not supported

要把springboot配置yml文件改成

spring:
  mvc:
   hiddenmethod:
      filter:
        enabled: true

springboot错误提示405状态

一、错误提示405状态截图

二、405状态的原因

springboot的自动配置中默认是关闭spring.mvc.hiddenmethod.filter 过滤器的,所以当我们提交的数据是put、post、delete方式时,我们使用的 _method 并不起作用。

spring.mvc.hiddenmethod.filter 自动配置:

三、解决方法

在 spring boot 的配置文件 application.properties 中将 hiddenmethod.filter 过滤器设置为启用即可。

spring.mvc.hiddenmethod.filter.enabled=true

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

《Springboot使用put、delete请求报错405的处理.doc》

下载本文的Word格式文档,以方便收藏与打印。