I make a put request

RestTemplate restTemplate = new RestTemplate();
restTemplate.put(new URI("http://localhost:8080/test"), dto);

which successfully hits the rest endpoint

@RequestMapping(value = "/test", method=RequestMethod.PUT)
public void test123(@RequestBody DTO dto) {
    System.out.println("phone:"+dto.getPhone()); 
}

but the "put" method on the client throws exception, even though the server is hit successfully and I don't expect return value.

Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 404 Not Found
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
    at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:589)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:547)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:518)
    at org.springframework.web.client.RestTemplate.put(RestTemplate.java:394)
    at com.my.Main.main(Main.java:45)

查看连接路径是否正确。

 

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2021-09-07
  • 2022-02-11
  • 2022-02-08
  • 2021-08-26
猜你喜欢
  • 2021-09-22
  • 2021-12-20
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
  • 2022-01-13
相关资源
相似解决方案