ntviet18
ntviet18

Reputation: 792

Feign recognized GET method as POST

I have a service defined as follow

class Echo {
  private String message; // getters and setters omitted
}

@RequestMapping("/app")
interface Resource {
  @RequestMapping(method = GET)
  Echo echo(@ModelAttribute Echo msg);
}

@RestController
class ResourceImpl implements Resource {
  @Override
  Echo echo(Echo msg) { return msg; }
}

and his client on a different application

@FeignClient(name = "app", url = "http://localhost:8080")
interface Client extends Resource {}

However, when I call resource method

@Autowired
private Resource client;

@Test
public void test() {
  Echo echo = new Echo();
  echo.setMessage("hello");
  client.echo(echo);
}

I got a confusing error message

feign.FeignException: status 405 reading ClientLocal#echo(Echo); content: {"timestamp":1512686240485,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/app"}

What I did wrong here?

Upvotes: 3

Views: 5860

Answers (1)

Oleksandr Yefymov
Oleksandr Yefymov

Reputation: 6509

Found the same issue and for me the reason of POST with GET mixing by Feign is usage of Object as request param

was with same error as yours:

@GetMapping("/followers/{userId}/id")
Page<String> getFollowersIds(@PathVariable String userId, Pageable pageable);

added @RequstParam for 2 argument fixed it, like:

@GetMapping("/followers/{userId}/id")
Page<String> getFollowersIds(@PathVariable String userId, @RequestParam Pageable pageable);

Upvotes: 4

Related Questions