提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.env.config; |
H |
2 |
|
|
3 |
import com.iailab.framework.env.core.fegin.EnvLoadBalancerClientFactory; |
|
4 |
import com.iailab.framework.env.core.fegin.EnvRequestInterceptor; |
|
5 |
import org.springframework.beans.factory.ObjectProvider; |
|
6 |
import org.springframework.boot.autoconfigure.AutoConfiguration; |
|
7 |
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|
8 |
import org.springframework.cloud.client.loadbalancer.LoadBalancerClientsProperties; |
|
9 |
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClientSpecification; |
|
10 |
import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfiguration; |
|
11 |
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; |
|
12 |
import org.springframework.context.annotation.Bean; |
|
13 |
|
|
14 |
import java.util.Collections; |
|
15 |
import java.util.List; |
|
16 |
|
|
17 |
/** |
|
18 |
* 多环境的 RPC 组件的自动配置 |
|
19 |
* |
|
20 |
* @author iailab |
|
21 |
*/ |
|
22 |
@AutoConfiguration |
|
23 |
@EnableConfigurationProperties(EnvProperties.class) |
|
24 |
public class IailabEnvRpcAutoConfiguration { |
|
25 |
|
|
26 |
// ========== Feign 相关 ========== |
|
27 |
|
|
28 |
/** |
|
29 |
* 创建 {@link EnvLoadBalancerClientFactory} Bean |
|
30 |
* |
|
31 |
* 参考 {@link LoadBalancerAutoConfiguration#loadBalancerClientFactory(LoadBalancerClientsProperties)} 方法 |
|
32 |
*/ |
|
33 |
@Bean |
|
34 |
public LoadBalancerClientFactory loadBalancerClientFactory(LoadBalancerClientsProperties properties, |
|
35 |
ObjectProvider<List<LoadBalancerClientSpecification>> configurations) { |
|
36 |
EnvLoadBalancerClientFactory clientFactory = new EnvLoadBalancerClientFactory(properties); |
|
37 |
clientFactory.setConfigurations(configurations.getIfAvailable(Collections::emptyList)); |
|
38 |
return clientFactory; |
|
39 |
} |
|
40 |
|
|
41 |
@Bean |
|
42 |
public EnvRequestInterceptor envRequestInterceptor() { |
|
43 |
return new EnvRequestInterceptor(); |
|
44 |
} |
|
45 |
|
|
46 |
} |