Am developing an application using Spring boot.I tried with all representations verbs like GET, POST , DELETE all are working fine too. By using PUT method, it\'s not supporting
Have you tried the following Request Mapping:
@RequestMapping(value = "/student/info", method = RequestMethod.PUT)
There's no need to separate the value and the Request Method for the URI.
Since Spring 4.3 you can use @PutMapping("url")
: https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/PutMapping.html
In this case it will be:
@PutMapping("/student/info")
public @ResponseBody String updateStudent(@RequestParam(value = "stdName")String stdName){
LOG.info(stdName);
return "ok";
}
This code will work fine. You must specify request mapping in class level or in function level.
@RequestMapping(value = "/student/info", method = RequestMethod.PUT)
public @ResponseBody String updateStudent(@RequestBody Student student){
LOG.info(student.toString());
return "ok";
}
I meet the same issue with spring boot 1.5.*,I fixed it by follow:
@RequestMapping(value = "/nick", method = RequestMethod.PUT)
public Result updateNick(String nick) {
return resultOk();
}
Add this bean
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() {
return new TomcatEmbeddedServletContainerFactory(){
@Override
protected void customizeConnector(Connector connector) {
super.customizeConnector(connector);
connector.setParseBodyMethods("POST,PUT,DELETE");
}
};
}
see also
https://stackoverflow.com/a/25383378/4639921
https://stackoverflow.com/a/47300174/4639921
you can add @RestController annotation before your class.
@RestController
@RequestMapping(value = "/v1/range")
public class RangeRestController {
}