diff --git a/CHANGELOG.md b/CHANGELOG.md index 976d3476e..98c0ab3c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,3 +15,4 @@ - build(deps): bump guava in /spring-cloud-tencent-dependencies - fix:fix reporting bug when port is -1. - fix:update guava version. +- fix:fix circuit breaker bean load order bug when using Nacos discovery. diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisCircuitBreakerAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisCircuitBreakerAutoConfiguration.java index 3be23d778..6ba7d4435 100644 --- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisCircuitBreakerAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisCircuitBreakerAutoConfiguration.java @@ -36,7 +36,6 @@ import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; @@ -98,7 +97,6 @@ public class PolarisCircuitBreakerAutoConfiguration { } @Bean - @ConditionalOnBean(RpcEnhancementReporterProperties.class) @ConditionalOnMissingBean(CircuitBreakerConfigModifier.class) public CircuitBreakerConfigModifier circuitBreakerConfigModifier(RpcEnhancementReporterProperties properties) { return new CircuitBreakerConfigModifier(properties); diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/ReactivePolarisCircuitBreakerAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/ReactivePolarisCircuitBreakerAutoConfiguration.java index 460df385d..23c3f281d 100644 --- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/ReactivePolarisCircuitBreakerAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/ReactivePolarisCircuitBreakerAutoConfiguration.java @@ -30,7 +30,6 @@ import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.cloud.client.circuitbreaker.Customizer; @@ -76,7 +75,6 @@ public class ReactivePolarisCircuitBreakerAutoConfiguration { } @Bean - @ConditionalOnBean(RpcEnhancementReporterProperties.class) @ConditionalOnMissingBean(CircuitBreakerConfigModifier.class) public CircuitBreakerConfigModifier reactiveCircuitBreakerConfigModifier(RpcEnhancementReporterProperties properties) { return new CircuitBreakerConfigModifier(properties); diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/org/springframework/cloud/openfeign/PolarisFeignCircuitBreakerTargeterAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/org/springframework/cloud/openfeign/PolarisFeignCircuitBreakerTargeterAutoConfiguration.java index 63b25fe2c..33754e6f3 100644 --- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/org/springframework/cloud/openfeign/PolarisFeignCircuitBreakerTargeterAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/org/springframework/cloud/openfeign/PolarisFeignCircuitBreakerTargeterAutoConfiguration.java @@ -23,6 +23,7 @@ import com.tencent.cloud.polaris.circuitbreaker.feign.PolarisCircuitBreakerNameR import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; import org.springframework.context.annotation.Bean; @@ -36,7 +37,7 @@ import org.springframework.context.annotation.Primary; */ @Configuration(proxyBeanMethods = false) @ConditionalOnClass({Targeter.class}) -@ConditionalOnProperty(value = "feign.circuitbreaker.enabled", havingValue = "true") +@ConditionalOnProperty(value = "feign.hystrix.enabled", havingValue = "true") @AutoConfigureBefore(FeignAutoConfiguration.class) @ConditionalOnPolarisCircuitBreakerEnabled public class PolarisFeignCircuitBreakerTargeterAutoConfiguration { @@ -44,6 +45,7 @@ public class PolarisFeignCircuitBreakerTargeterAutoConfiguration { @Bean @Primary @ConditionalOnBean(CircuitBreakerFactory.class) + @ConditionalOnMissingBean(Targeter.class) public Targeter polarisFeignCircuitBreakerTargeter(CircuitBreakerFactory circuitBreakerFactory, PolarisCircuitBreakerNameResolver circuitBreakerNameResolver) { return new PolarisFeignCircuitBreakerTargeter(circuitBreakerFactory, circuitBreakerNameResolver); } diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/resources/META-INF/spring.factories b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/resources/META-INF/spring.factories index 41da60a9e..3f7eb9744 100644 --- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/resources/META-INF/spring.factories @@ -5,4 +5,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerFeignClientAutoConfiguration,\ org.springframework.cloud.openfeign.PolarisFeignCircuitBreakerTargeterAutoConfiguration org.springframework.cloud.bootstrap.BootstrapConfiguration=\ - com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerBootstrapConfiguration + com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerBootstrapConfiguration,\ + org.springframework.cloud.openfeign.PolarisFeignCircuitBreakerTargeterAutoConfiguration diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/beanprocessor/PolarisLoadBalancerCompositeRuleBeanPostProcessor.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/beanprocessor/PolarisLoadBalancerCompositeRuleBeanPostProcessor.java index 7b9e8dc6d..66f4119f9 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/beanprocessor/PolarisLoadBalancerCompositeRuleBeanPostProcessor.java +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/beanprocessor/PolarisLoadBalancerCompositeRuleBeanPostProcessor.java @@ -23,6 +23,7 @@ import java.util.List; import com.netflix.client.config.IClientConfig; import com.netflix.loadbalancer.AbstractLoadBalancerRule; import com.tencent.cloud.common.util.BeanFactoryUtils; +import com.tencent.cloud.polaris.context.PolarisSDKContextManager; import com.tencent.cloud.polaris.loadbalancer.config.PolarisLoadBalancerProperties; import com.tencent.cloud.polaris.router.PolarisLoadBalancerCompositeRule; import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor; @@ -47,7 +48,8 @@ public class PolarisLoadBalancerCompositeRuleBeanPostProcessor implements BeanPo @Override public Object postProcessBeforeInitialization(@NonNull Object bean, @NonNull String beanName) throws BeansException { if (bean instanceof AbstractLoadBalancerRule) { - RouterAPI routerAPI = beanFactory.getBean(RouterAPI.class); + PolarisSDKContextManager polarisSDKContextManager = beanFactory.getBean(PolarisSDKContextManager.class); + RouterAPI routerAPI = polarisSDKContextManager.getRouterAPI(); PolarisLoadBalancerProperties polarisLoadBalancerProperties = beanFactory.getBean(PolarisLoadBalancerProperties.class); IClientConfig iClientConfig = beanFactory.getBean(IClientConfig.class); List requestInterceptors = BeanFactoryUtils.getBeans(beanFactory, RouterRequestInterceptor.class); diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/pom.xml b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/pom.xml index 8b70623c4..ff82b5d9a 100644 --- a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/pom.xml +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/pom.xml @@ -18,16 +18,22 @@ spring-boot-starter-web - - - - + + com.tencent.cloud + spring-cloud-starter-tencent-polaris-router + com.tencent.cloud spring-cloud-starter-tencent-discovery-adapter-plugin + + + com.tencent.cloud + spring-cloud-starter-tencent-polaris-circuitbreaker + + org.springframework.cloud spring-cloud-starter-openfeign diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-feign-example/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-feign-example/src/main/resources/bootstrap.yml index 2781ab68b..f71696fc2 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-feign-example/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-feign-example/src/main/resources/bootstrap.yml @@ -12,7 +12,7 @@ spring: enabled: true feign: - circuitbreaker: + hystrix: enabled: true logging: diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java index 4ed3dfbc8..9886eaa13 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java @@ -188,6 +188,7 @@ public class RpcEnhancementAutoConfiguration { public PolarisLoadBalancerRequestTransformer polarisLoadBalancerRequestTransformer() { return new PolarisLoadBalancerRequestTransformer(); } + } /**