parent
aeda6699df
commit
0cd097f65c
@ -1,17 +1,35 @@
|
|||||||
package com.example.config;
|
package ${domain}.config;
|
||||||
|
|
||||||
|
import ${domain}.frame.auth.LocalData;
|
||||||
|
import ${domain}.frame.utils.MapperUtil;
|
||||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpRequest;
|
||||||
|
import org.springframework.http.client.ClientHttpRequestExecution;
|
||||||
|
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||||
|
import org.springframework.http.client.ClientHttpResponse;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class CloudConfig {
|
public class CloudConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@LoadBalanced
|
@LoadBalanced
|
||||||
public RestTemplate restTemplate() {
|
public RestTemplate restTemplate() {
|
||||||
return new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
restTemplate.setInterceptors(Collections.singletonList(new ClientHttpRequestInterceptor() {
|
||||||
|
@Override
|
||||||
|
public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {
|
||||||
|
HttpHeaders headers = httpRequest.getHeaders();
|
||||||
|
headers.add("token", MapperUtil.toJson(LocalData.getToken()));
|
||||||
|
return clientHttpRequestExecution.execute(httpRequest, bytes);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
return restTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue