How do I log response in Spring RestTemplate?

后端 未结 5 1363
滥情空心
滥情空心 2020-12-09 18:12

I am using RestTemplate to make calls to a web service.

String userId = restTemplate.getForObject(createUserUrl, String.class);

If this fai

5条回答
  •  無奈伤痛
    2020-12-09 19:08

    Configure your logging as follows:

    log4j.logger.org.springframework.web.client=DEBUG
    

    Then use a curl command to see the output, eg

    curl  -H 'Accept: application/xml' -H 'Content-Type: application/xml' http://localhost:8080/ser/data
    

    By default, restTemplate uses HttpURlConnection (via SimpleClientHttpRequest), so you might need to switch to jakarta httpclient to see the log statement. Otherwise the above log configuration will out show you the response

        
            
        
        
            
            
    ...
    

提交回复
热议问题