Feign recognized GET method as POST

家住魔仙堡 提交于 2021-01-05 04:47:15

问题


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?


回答1:


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);


来源:https://stackoverflow.com/questions/47705024/feign-recognized-get-method-as-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!