1. 程式人生 > >message:Request method 'POST' not supported

message:Request method 'POST' not supported

message:Request method ‘POST’ not supported

There was an unexpected error (type=Internal Server Error, status=500).
status 405 reading UserFeignClient#getUser(User); content: {“timestamp”:“2018-09-07T09:01:14.290+0000”,“status”:405,“error”:“Method Not Allowed”,“message”:“Request method ‘POST’ not supported”,“path”:"/feign-get-user"}

  • 錯誤原因:
    該請求不會成功,只要引數是複雜物件,即使指定了是GET方法,feign依然會以POST方法進行傳送請求。可能是我沒找到相應的註解或使用方法錯誤。

  • 解決辦法:

	// 該請求不會成功,只要引數是複雜物件,即使指定了是GET方法,feign依然會以POST方法進行傳送請求。可能是我沒找到相應的註解或使用方法錯誤。
	@RequestMapping(method = RequestMethod.GET, value = "/feign-get-user")
	public User getUser(User user);
	
	//正確用法
	@RequestMapping(method = RequestMethod.GET, value = "/feign-get-user")
	public User getUser(@RequestParam("id") Long id, @RequestParam("username") String username, @RequestParam("age") String age);
}