【发布时间】:2017-02-02 13:32:40
【问题描述】:
我的 Spring Boot REST 控制器中有 2 种方法
这是我的 REST 控制器代码
@RestController
public class MainRestController {
@RequestMapping(value = "/",method=RequestMethod.POST)
public String startMigration(){
return "POSt";
}
@RequestMapping(value = "/",method=RequestMethod.PATCH)
public String PUT(){
return "PUT";
}
/*
* If i commnet this method and un comment following method it will run
* */
@RequestMapping(value = "/{name}",method=RequestMethod.PUT)
public String PATCH(@PathVariable String name){
return "PATCH";
}
/*@RequestMapping(value = "/",method=RequestMethod.PATCH)
public String PATCH(){
return "PATCH";
}*/
@RequestMapping(value = "/",method=RequestMethod.DELETE)
public String DELETE(){
return "DELETE";
}
}
这是我的控制器代码
@Controller
public class MainController {
@RequestMapping(value = "/",method=RequestMethod.GET)
public String getMainPage(){
return "index.html";
}
}
现在的问题是当我点击 PATCH 请求时 http://localhost:8080/ 它返回
{
"timestamp": 1486041782895,
"status": 405,
"error": "Method Not Allowed",
"exception":"org.springframework.web.HttpRequestMethodNotSupportedException",
"message": "Request method 'PATCH' not supported",
"path": "/"
}
当我点击 GET 请求 http://localhost:8080/ 它返回
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Feb 02 19:00:18 IST 2017
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'GET' not supported
谁能告诉我原因?
【问题讨论】:
-
您能否添加一个展示 SB 应用程序的示例要点?
-
我已经添加了有问题的两个类代码
标签: spring-boot spring-restcontroller