|
7 | 7 | import org.springframework.beans.factory.annotation.Autowired; |
8 | 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
9 | 9 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
| 10 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; |
10 | 11 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
11 | 12 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; |
12 | 13 | import org.springframework.context.annotation.Bean; |
|
19 | 20 | @ConditionalOnClass(value = RestTemplate.class) |
20 | 21 | public class GrayRestTemplateAutoConfiguration { |
21 | 22 |
|
22 | | - @Autowired |
23 | | - private GrayRequestProperties grayRequestProperties; |
24 | | - @Autowired |
25 | | - private RibbonConnectionPoint ribbonConnectionPoint; |
26 | 23 |
|
| 24 | + @ConditionalOnMissingBean(RestTemplate.class) |
| 25 | + @ConditionalOnClass({LoadBalanced.class}) |
| 26 | + public static class LoadBalancedRestTemplateConfiguration { |
27 | 27 |
|
28 | | - @Bean |
29 | | - @LoadBalanced |
30 | | - @ConditionalOnMissingBean |
31 | | - public RestTemplate restTemplate() { |
32 | | - RestTemplate restTemplate = new RestTemplate(); |
33 | | -// restTemplate.getInterceptors().add(grayClientHttpRequestIntercptor); |
34 | | - return restTemplate; |
| 28 | + @Autowired |
| 29 | + private GrayRequestProperties grayRequestProperties; |
| 30 | + @Autowired |
| 31 | + private RibbonConnectionPoint ribbonConnectionPoint; |
| 32 | + |
| 33 | + @Bean |
| 34 | + @LoadBalanced |
| 35 | + public RestTemplate restTemplate() { |
| 36 | + RestTemplate restTemplate = new RestTemplate(); |
| 37 | + return restTemplate; |
| 38 | + } |
| 39 | + |
| 40 | + @Bean |
| 41 | + public GrayClientHttpRequestIntercptor grayClientHttpRequestIntercptor(@LoadBalanced List<RestTemplate> restTemplates) { |
| 42 | + GrayClientHttpRequestIntercptor intercptor = new GrayClientHttpRequestIntercptor( |
| 43 | + grayRequestProperties, ribbonConnectionPoint); |
| 44 | + restTemplates.forEach(restTemplate -> restTemplate.getInterceptors().add(intercptor)); |
| 45 | + return intercptor; |
| 46 | + } |
35 | 47 | } |
36 | 48 |
|
37 | 49 |
|
38 | | - @Bean |
39 | | - public GrayClientHttpRequestIntercptor grayClientHttpRequestIntercptor(@LoadBalanced List<RestTemplate> restTemplates) { |
40 | | - GrayClientHttpRequestIntercptor intercptor = new GrayClientHttpRequestIntercptor( |
41 | | - grayRequestProperties, ribbonConnectionPoint); |
42 | | - restTemplates.forEach(restTemplate -> restTemplate.getInterceptors().add(intercptor)); |
43 | | - return intercptor; |
| 50 | + @ConditionalOnMissingBean(RestTemplate.class) |
| 51 | + @ConditionalOnMissingClass({"org.springframework.cloud.client.loadbalancer.LoadBalanced"}) |
| 52 | + public static class RestTemplateConfiguration { |
| 53 | + @Bean |
| 54 | + public RestTemplate restTemplate() { |
| 55 | + RestTemplate restTemplate = new RestTemplate(); |
| 56 | + return restTemplate; |
| 57 | + } |
44 | 58 | } |
45 | 59 |
|
46 | 60 |
|
47 | 61 | @Configuration |
48 | 62 | @ConditionalOnProperty(value = "gray.request.track.enabled", matchIfMissing = true) |
49 | 63 | public static class GrayTrackRestTemplateConfiguration { |
50 | 64 |
|
51 | | - |
52 | 65 | @Bean |
53 | 66 | public RestTemplateRequestInterceptor restTemplateRequestInterceptor() { |
54 | 67 | return new RestTemplateRequestInterceptor(); |
|
0 commit comments