2016-05-06 57 views
0

我已经设置了弹簧集成应用程序,并且希望使用ClientHttpRequestInterceptor来记录出站请求。 设置如下。 我使用curl发送了Http-get并获得了结果,但在调试应用程序时,方法CustomClientHttpRequestInterceptor.intercept()永远不会被调用。Spring集成:发送请求时不调用ClientHttpRequestInterceptor拦截()方法

我一定在设置中遗漏了一些东西。感谢您的帮助。

配置:

<bean id="customRT" class="org.springframework.web.client.RestTemplate"> 
    <property name="interceptors"> 
     <list> 
      <bean class="hello.CustomClientHttpRequestInterceptor" /> 
     </list> 
    </property> 
</bean> 

<int:chain...> 
    <int:header-enricher.... 
    <int-http:outbound-gateway url="http://example.com/vhosts" 
          rest-template="customRT" 
          http-method="GET"/> 
</int:chain> 

public class CustomClientHttpRequestInterceptor implements ClientHttpRequestInterceptor { 
    Logger logger = LoggerFactory.getLogger(this.getClass()); 

    @Override 
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) 
     throws IOException { 
     logger.info("request.getURI().toString());  
     return execution.execute(request, body); 
    } 

回答

0

的配置和代码是否正确。我忘记了安装了缓存,这就是为什么intercept()方法永远不会被调用的原因。