Spring REST Interceptor with dynamic values
<p><strong>Question in short:</strong> How can I pass a dynamic value to Spring REST interceptor after the RestTemplate is Autowired?</p>

<p><strong>Now a detailed explanation:</strong></p>

<p>I have a Spring REST interceptor as below:</p>

<pre><code>public class HeaderRequestInterceptor implements ClientHttpRequestInterceptor  {

  private final String headerName;

  private final String headerValue;

  public HeaderRequestInterceptor(final String headerName, final String headerValue) {
    this.headerName = headerName;
    this.headerValue = headerValue;
  }

  public ClientHttpResponse intercept(final HttpRequest request, final byte[] body, final ClientHttpRequestExecution execution) throws IOException {
    HttpRequest wrapper = new HttpRequestWrapper(request);
    wrapper.getHeaders().set(headerName, headerValue);
    return execution.execute(wrapper, body);
  }
}
</code></pre>

<p>And then I configure my RestTemplate as below with the above interceptor:</p>

<pre><code>@Bean
 public RestTemplate getRestTemplate() {
    List&lt;ClientHttpRequestInterceptor&gt; interceptors = new ArrayList&lt;ClientHttpRequestInterceptor&gt;();
    interceptors.add(new HeaderRequestInterceptor(&lt;&lt;MY-CUSTOM-HEADER&gt;&gt;, &lt;&lt;MY-DYNAMIC-VALUE&gt;&gt;));

    final RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory());
    restTemplate.setInterceptors(interceptors);
    return restTemplate;
}
</code></pre>

<p>Please look at the way I am creating the interceptor. MY-CUSTOM-HEADER is a constant, but MY-DYNAMIC-VALUE can change for every request. How can I make the interceptor take dynamic value?</p>

<p>PS: This is a standalone spring application (not web). It's a kind of client library that will be used to make REST calls.</p>