mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge pull request #550 from mercyblitz/master
Dubbo Spring Cloud Update
This commit is contained in:
commit
adcd590b58
@ -35,6 +35,7 @@ import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceFactor
|
|||||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
|
||||||
import org.springframework.cloud.client.loadbalancer.RestTemplateCustomizer;
|
import org.springframework.cloud.client.loadbalancer.RestTemplateCustomizer;
|
||||||
|
import org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
@ -56,7 +57,7 @@ import java.util.Map;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass(name = {"org.springframework.web.client.RestTemplate"})
|
@ConditionalOnClass(name = {"org.springframework.web.client.RestTemplate"})
|
||||||
@AutoConfigureAfter(name = {"org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration"})
|
@AutoConfigureAfter(name = {"org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration"})
|
||||||
public class DubboLoadBalancedRestTemplateAutoConfiguration implements BeanClassLoaderAware {
|
public class DubboLoadBalancedRestTemplateAutoConfiguration implements BeanClassLoaderAware, SmartInitializingSingleton {
|
||||||
|
|
||||||
private static final Class<DubboTransported> DUBBO_TRANSPORTED_CLASS = DubboTransported.class;
|
private static final Class<DubboTransported> DUBBO_TRANSPORTED_CLASS = DubboTransported.class;
|
||||||
|
|
||||||
@ -65,9 +66,12 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements BeanClass
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DubboServiceMetadataRepository repository;
|
private DubboServiceMetadataRepository repository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired(required = false)
|
||||||
private LoadBalancerInterceptor loadBalancerInterceptor;
|
private LoadBalancerInterceptor loadBalancerInterceptor;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private RetryLoadBalancerInterceptor retryLoadBalancerInterceptor;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ConfigurableListableBeanFactory beanFactory;
|
private ConfigurableListableBeanFactory beanFactory;
|
||||||
|
|
||||||
@ -86,6 +90,17 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements BeanClass
|
|||||||
|
|
||||||
private ClassLoader classLoader;
|
private ClassLoader classLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link ClientHttpRequestInterceptor} bean that may be {@link LoadBalancerInterceptor} or {@link RetryLoadBalancerInterceptor}
|
||||||
|
*/
|
||||||
|
private ClientHttpRequestInterceptor loadBalancerInterceptorBean;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterSingletonsInstantiated() {
|
||||||
|
loadBalancerInterceptorBean = retryLoadBalancerInterceptor != null ?
|
||||||
|
retryLoadBalancerInterceptor :
|
||||||
|
loadBalancerInterceptor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapt the {@link RestTemplate} beans that are annotated {@link LoadBalanced @LoadBalanced} and
|
* Adapt the {@link RestTemplate} beans that are annotated {@link LoadBalanced @LoadBalanced} and
|
||||||
@ -140,7 +155,7 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements BeanClass
|
|||||||
|
|
||||||
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(restTemplate.getInterceptors());
|
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(restTemplate.getInterceptors());
|
||||||
|
|
||||||
int index = interceptors.indexOf(loadBalancerInterceptor);
|
int index = loadBalancerInterceptorBean == null ? -1 : interceptors.indexOf(loadBalancerInterceptorBean);
|
||||||
|
|
||||||
index = index < 0 ? 0 : index;
|
index = index < 0 ? 0 : index;
|
||||||
|
|
||||||
@ -157,4 +172,5 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements BeanClass
|
|||||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||||
this.classLoader = classLoader;
|
this.classLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -96,41 +96,19 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
<!-- Spring Cloud Nacos Service Discovery -->
|
||||||
|
|
||||||
<profiles>
|
|
||||||
|
|
||||||
<!-- Nacos -->
|
|
||||||
<profile>
|
|
||||||
<id>nacos</id>
|
|
||||||
<activation>
|
|
||||||
<activeByDefault>true</activeByDefault>
|
|
||||||
</activation>
|
|
||||||
<dependencies>
|
|
||||||
<!-- Nacos Service Discovery -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
<!-- Spring Cloud Eureka Service Discovery -->
|
||||||
<id>eureka</id>
|
|
||||||
<dependencies>
|
|
||||||
<!-- Eureka Service Discovery -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<!-- Zookeeper -->
|
<!-- Spring Cloud Zookeeper Service Discovery -->
|
||||||
<profile>
|
|
||||||
<id>zookeeper</id>
|
|
||||||
<dependencies>
|
|
||||||
<!-- Zookeeper Service Discovery -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||||
@ -161,22 +139,14 @@
|
|||||||
<artifactId>curator-framework</artifactId>
|
<artifactId>curator-framework</artifactId>
|
||||||
<version>${curator.version}</version>
|
<version>${curator.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
<!-- Spring Cloud Consul Service Discovery -->
|
||||||
<id>consul</id>
|
|
||||||
<dependencies>
|
|
||||||
<!-- Spring Cloud Consul -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
|
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
|
||||||
<version>${spring-cloud-consul.version}</version>
|
<version>${spring-cloud-consul.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</profile>
|
|
||||||
|
|
||||||
</profiles>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -21,6 +21,18 @@
|
|||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Cloud Open Feign -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Retry -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.retry</groupId>
|
||||||
|
<artifactId>spring-retry</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Sample API -->
|
<!-- Sample API -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
@ -28,12 +40,6 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Cloud Open Feign -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user