标签:idt ring bottom red over uri amp lis 使用
public class HeaderRequestInterceptor implements ClientHttpRequestInterceptor {
private final String headerName;
private final String headerValue;
public HeaderRequestInterceptor(String headerName, String headerValue) {
this.headerName = headerName;
this.headerValue = headerValue;
}
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().set(headerName, headerValue);
return execution.execute(request, body);
}
}
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate() {
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
interceptors.add(new HeaderRequestInterceptor("token", "123"));
RestTemplate restTemplate = new RestTemplate();
restTemplate.setInterceptors(interceptors);
return restTemplate;
}
}
@Autowired
private RestTemplate restTemplate;
参考
标签:idt ring bottom red over uri amp lis 使用
原文地址:https://www.cnblogs.com/victorbu/p/12708340.html