雷丰阳Springboot视频培训教程问题解决记录之六——奇怪的Request method 'POST' not supported 405错误
2019-04-16 20:37
531 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Lswx2006/article/details/89341278
最近学习了RESTful服务的构建,在试验@DeleteMapping 删除功能的时候,出现了很奇怪的错误。
点击删除按钮,就会出现如下错误信息:
Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'POST' not supported.
查了一天文档,没有结果,后来发现教程中Springboot 1.5.10中的WebMvcConfigurerAdapter 方法在2.1X版本中已经不推荐使用了,于是使用了 WebMvcConfigurationSupport 替代。
WebMvcConfigurationSupport 指示SpringBoot 要完全接管SpringMVC的配置,这意味着HiddenHttpMethodFilter 不再自动配置。因此,DELETE 请求被作为POST请求处理。
正确的用法是自己配置 HiddenHttpMethodFilter bean或者使用SpringBoot的自动配置,推荐使用后者。将MyMvcConfig 修改为实现WebMvcConfigurer ,问题解决。
修改后的代码如下:
[code]@Configuration public class MyMvcConfig implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**") .excludePathPatterns("/", "/index.html", "/user/login", "/webjars/**", "/asserts/**"); } @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index"); registry.addViewController("/index.html").setViewName("index"); registry.addViewController("/main.html").setViewName("dashboard"); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/"); registry.addResourceHandler("/asserts/**") .addResourceLocations("classpath:/static/asserts/"); } }
相关文章推荐
- 雷丰阳Springboot视频培训教程问题解决记录之九——Spring定时任务及Encountered invalid @Scheduled method For Input String错误
- 雷丰阳Springboot视频培训教程问题解决记录之十——邮件发送以及java.lang.IllegalStateException: Not in multipart mode错误
- 雷丰阳Springboot视频培训教程问题解决记录之七——修改默认配置的方法
- springmvc解决 405 request method post not supported(Request method 'POST' not supported)
- Spring Boot出现Request method 'POST' not supported,深入源码原因分析
- 解决Spring Boot中,通过filter打印post请求的 request body 问题
- springboot 数据源循环依赖问题 eureka服务无法被调用,错误代码405
- VUE+SpringBoot POST传输报400错误(Invalid character found in the request target. The valid characters are)
- 解决使用Spring Boot、Multipartfile上传文件路径错误问题
- Spring MVC出现POST 400 Bad Request &405 Request method 'GET' not supported
- HTTP Status 405 - Request method 'POST' not supported (Spring MVC)
- 解决使用Spring Boot、Multipartfile上传文件路径错误问题
- spring boot 用war包部署到tomcat下详细教程(解决缺少web.xml报错的问题)
- spring boot新手教程之使用FastJson解析JSON数据以及解决返回中文乱码问题
- 通过spring boot 设置tomcat解决 post参数限制问题
- SpringBoot 调用ajax POST 方法报Request method 'POST' not supported解决方法
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported解决!
- 在pring框架出现 405 request method post not supported 的解决方法
- springMVC:org.springframework.web.servlet.PageNotFound.handleHttpRequestMethodNotSupported Request method 'POST' not supported
- SpringMVC Request method 'GET' not supported 解决办法