大佬教程收集整理的这篇文章主要介绍了Spring Boot 405 POST方法不受支持?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
RestController注释定义中存在错误。根据文档,它是:
这意味着您输入的值(“ / BACkoffice / Tags”)是控制器的名称,而不是其可用路径。
添加@requestMapPing("/BACkoffice/Tags")
控制器的类,并从@RestController
注释中删除值。
完全正常工作的示例,根据注释它不起作用-请尝试使用此代码-并从IDE本地运行。
buildscript { ext { springBootVersion = '1.2.5.RELEASE' } repositorIEs { mavenCentral() } dependencIEs { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") classpath("io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'IDea' apply plugin: 'spring-boot' apply plugin: 'io.spring.dependency-management' jar { basename = 'demo' version = '0.0.1-SNAPSHOT' } sourceCompatibility = 1.8 targetCompatibility = 1.8 repositorIEs { mavenCentral() } dependencIEs { compile("org.springframework.boot:spring-boot-starter-web") TESTCompile("org.springframework.boot:spring-boot-starter-test") } eclipse { classpath { containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER') containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.deBUG.ui.launcher.StandardVMType/JavaSE-1.8' } } task wrapper(type: Wrapper) { gradLeversion = '2.3' }
@H_419_31@
package demo; import com.fasterxml.jackson.Annotation.JsonCreator; import com.fasterxml.jackson.Annotation.JsonProperty; public class Tag { private final String tagname; @JsonCreator public Tag(@JsonProperty("tagname") String tagName) { this.tagname = tagname; } public String getTagname() { return tagname; } @OverrIDe public String toString() { final StringBuilder sb = new StringBuilder("Tag{"); sb.append("tagname='").append(tagName).append('\''); sb.append('}'); return sb.toString(); } }
@H_419_31@
package demo; import org.springframework.web.bind.Annotation.requestbody; import org.springframework.web.bind.Annotation.requestMapPing; import org.springframework.web.bind.Annotation.requestMethod; import org.springframework.web.bind.Annotation.RestController; import java.util.List; @RestController @requestMapPing("/BACkoffice/Tags") public class SampleController { @requestMapPing(value = "/add", method = requestMethod.POST) public voID add(@requestbody List<Tag> Tags) { System.out.println(tags); } }
@H_419_31@
package demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static voID main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
@H_419_31@解决方法
Spring Boot MVC如何不支持POST方法?我正在尝试实现一个简单的post方法,该方法接受实体列表:这是我的代码
@RestController(value="/BACkoffice/tags") public class TagsController { @requestMapping(value = "/add",method = requestMethod.POST) public void add(@requestBody List<Tag> keywords) { tagsservice.add(keywords); } }
像这样点击此网址:
http://localhost:8090/BACkoffice/tags/add
请求正文:
[{"tagName":"qweqwe"},{"tagName":"zxczxczx"}]
我收到:
{ "timestamp": 1441800482010,"status": 405,"error": "Method Not Allowed","exception": "org.springframework.web.httprequestMethodNotSupportedException","message": "request method 'POST' not supported","path": "/BACkoffice/tags/add" }
编辑 :
调试Spring Web请求处理程序
public void handlerequest(httpServletrequest request,httpServletResponse responsE) throws ServletException,IOException { this.checkrequest(request); protected final void checkrequest(httpServletrequest request) throws ServletException { String method = request.getMethod(); if(this.supportedMethods != null && !this.supportedMethods.contains(method)) { throw new httprequestMethodNotSupportedException(method,StringUtils.toStringArray(this.supportedMethods)); } else if(this.requireSession && request.getSession(false) == null) { throw new httpSessionrequiredException("Pre-exisTing session required but none found"); } }
以上是大佬教程为你收集整理的Spring Boot 405 POST方法不受支持?全部内容,希望文章能够帮你解决Spring Boot 405 POST方法不受支持?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。