title: RestTemplate Interceptor
body: <p>I'm currently trying to incorporate a <code>HandlerInterceptorAdapter</code> but it's not getting registered and comparing it to other answers is tough because everyone is using something different. And I'm aware WebMvcConfigureAdapter is deprecated, some versioning is beyond my control for the scope of the project,  see usage specs below.</p>
  
  <p>Can someone please provide some guidance on incorporating interceptors with a RestTemplate (that's not ClientHttpRequestInterceptor).</p>
  
  <p>Main:</p>
  
  <pre class="lang-java prettyprint-override"><code>@SpringBootApplication
  @EnableRetry
  public class Application extends SpringBootServletInitializer {
  
    public static void main(String[] args) {
  
     ApplicationContext ctx = SpringApplication.run(Application.class, args);
  
    }
  
  
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
  
      return applicationBuilder.sources(Application.class);
  
    }
  
    @Bean
    private RestTemplate restTemplate(){
      Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("redacted", 8080));
  
      SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
      simpleClientHttpRequestFactory.setProxy(proxy);
      simpleClientHttpRequestFactory.setOutputStreaming(false);
  
      RestTemplate template = new RestTemplate();
      template.setErrorHandler(new MyResponseErrorHandler());
  
      return template;
    }
  }
  </code></pre>
  
  <p>Interceptor  : com.example.foo.config.request.interceptor</p>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  public class MyInterceptor extends HandlerInterceptorAdapter {
  
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
      System.out.println("INTERCEPTED");
      return super.preHandle(request, response, handler);
    }
  }
  </code></pre>
  
  <p>InterceptorConfig : com.example.foo.config.request.interceptor</p>
  
  <pre class="lang-java prettyprint-override"><code>@Configuration
  public class InterceptorConfig extends WebMvcConfigurerAdapter  {
  
    @Bean
    MyInterceptor myInterceptor() {
      return new MyInterceptor();
    }
  
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
      super.addInterceptors(registry);
      System.out.println("Adding interceptor");
      registry.addInterceptor(myInterceptor());
    }
  
  }
  
  </code></pre>
  
  <p>"Adding interceptor" does get logged so I know the configs are being scanned. I just can't get any interceptor logic to log.</p>
  
  <p>Using:</p>
  
  <ul>
  <li>Spring Boot v1.5.15</li>
  <li>Spring Version: 4.3.18.RELEASE</li>
  </ul>