【发布时间】:2015-11-18 02:58:51
【问题描述】:
我的 Spring Boot 应用程序中有以下列出的 loggingInterceptor。每当调用 REST 服务时,都会调用此拦截器。我看到第一个 2 sysout 语句被立即打印,第 3 个 sysout 语句在 REST 调用之后被打印。是否仅在调用 getBody() 时才进行 REST 调用?请你能解释一下这是如何工作的吗?谢谢。
public class LoggingInterceptor implements ClientHttpRequestInterceptor {
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
System.out.println(" Before Calling Execute in LoggingInterceptor " + new Date());
ClientHttpResponse response = execution.execute(request, body);
System.out.println(" After Calling Execute in LoggingInterceptor " + new Date());
InputStream responseStream = response.getBody();
System.out.println(" After getBody() " + new Date());
}
}
【问题讨论】:
标签: java spring spring-boot