30 lines
1.0 KiB
Java
30 lines
1.0 KiB
Java
package com.baeldung.sampleapp.config;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
import com.baeldung.sampleapp.interceptors.RestTemplateHeaderModifierInterceptor;
|
|
|
|
@Configuration
|
|
public class RestClientConfig {
|
|
|
|
@Bean
|
|
public RestTemplate restTemplate() {
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
|
|
if (CollectionUtils.isEmpty(interceptors)) {
|
|
interceptors = new ArrayList<ClientHttpRequestInterceptor>();
|
|
}
|
|
interceptors.add(new RestTemplateHeaderModifierInterceptor());
|
|
restTemplate.setInterceptors(interceptors);
|
|
return restTemplate;
|
|
}
|
|
}
|