0

I have a method in one of my webservices that accepts both PUT and POST. This is because we started using PUT but later we needed to support POST too (for a new service).

@RequestMapping(
        value = "/endpointURL",
        method = {RequestMethod.PUT, RequestMethod.POST})

I am trying to create a test application that calls this method, but Spring throws an Autowiring error during startup with the following error:

java.lang.IllegalStateException: Method [name] can only contain 1 method field. Found: [PUT, POST]

Both the Spring and Feign versions are the same in both applications (webservice with this endpoint, and testing application).

Any ideas on how to fix it please?

Thank you!

slayers_88
  • 63
  • 5
  • Please add the full stacktrace. I dount it is Spring MVC but rather Feign that requires a single method (else how should it know what to pick). – M. Deinum Mar 04 '19 at 10:44

2 Answers2

0

Method supports various HTTP method as below. Could you post your class source code. I think you should have another problem. Maybe duplicated path or else.

@RequestMapping("/v1/echo")
@RestController
public class EchoApi {

    @RequestMapping(value = "/", method = { RequestMethod.PUT, RequestMethod.POST })
    public ResponseEntity<String> echo(@RequestBody String body){
        System.err.println(body);
        return new ResponseEntity<String>(body, HttpStatus.OK);
    }

}
codiallo
  • 173
  • 4
0

In the end it was due to the Feign version we were using. It's fixed after version 10. Will close this topic. Thanks!

slayers_88
  • 63
  • 5