6

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 in spring boot. Whether I need to add any new configuration.

Put method works only the request not have any parameters. If i add any query parameter or form data it doesnt work. Kindly any expertize will help me to solve this issue.

@RequestMapping("/student/info")
@RequestMapping(method = RequestMethod.PUT)
public @ResponseBody String updateStudent(@RequestParam(value = "stdName")String stdName){
    LOG.info(stdName);
    return "ok";
}

Request method 'PUT' not supported

Aravind Cheekkallur
  • 3,157
  • 6
  • 27
  • 41
  • What version of Spring are you working with? And what does the URL look like that "doesn't work" ? – Gimby Oct 29 '14 at 08:46
  • Spring boot 1.1.1 and URL is like this http://localhost:8000/student/info?stdName=test – Aravind Cheekkallur Oct 29 '14 at 08:50
  • You have 2 request mappings for a single method merge them into a single one. `@RequestMapping(value="/student/info", method=RequestMethod.PUT)`. Next to that you probably also need to add the `HttpPutFormContentFilter` to yuor list of filters. – M. Deinum Oct 29 '14 at 09:09

5 Answers5

12

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";
}
Pratheesh
  • 161
  • 6
1

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.

blackpanther
  • 10,998
  • 11
  • 48
  • 78
  • 1
    @AravindCheekkallur what version of Spring are you using and have you added the filter `HttpPutFormContentFilter`. Also, have you got your Boot configuration Java class - it should have `@EnableAutoConfiguration` – blackpanther Oct 29 '14 at 09:29
0

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";
}
kozielt
  • 36
  • 5
0

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

GreatC
  • 342
  • 4
  • 9
-1

you can add @RestController annotation before your class.

@RestController
@RequestMapping(value = "/v1/range")
public class RangeRestController {
}
PPHAC
  • 1