From a7672c41f38700a7403d6db28ebb5a8b9e76bdf2 Mon Sep 17 00:00:00 2001 From: Hligaty <1970316213@qq.com> Date: Sat, 16 Sep 2023 16:30:07 +0800 Subject: [PATCH 1/2] Refactoring:remove invalid @AutoConfigureAfter and @AutoConfigureBefore from discovery client automatic configuration. (#1115) --- CHANGELOG.md | 1 + .../discovery/PolarisDiscoveryClientConfiguration.java | 6 ------ .../PolarisReactiveDiscoveryClientConfiguration.java | 7 ------- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a66773a1..239001d40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,3 +4,4 @@ - [fix:the polaris config relation non-daemon thread should stop when application fails to start.](https://github.com/Tencent/spring-cloud-tencent/pull/1100) - [fix:fix feign url bug when using sleuth.](https://github.com/Tencent/spring-cloud-tencent/pull/1096) - [fix: dynamic routing using cookies.](https://github.com/Tencent/spring-cloud-tencent/pull/1097) +- [Refactoring:remove invalid @AutoConfigureAfter and @AutoConfigureBefore from discovery client automatic configuration.](https://github.com/Tencent/spring-cloud-tencent/pull/1115) diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryClientConfiguration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryClientConfiguration.java index 63001d01d..25f7c53fc 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryClientConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryClientConfiguration.java @@ -17,12 +17,8 @@ package com.tencent.cloud.polaris.discovery; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.cloud.client.CommonsClientAutoConfiguration; import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled; import org.springframework.cloud.client.discovery.DiscoveryClient; -import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -34,8 +30,6 @@ @Configuration(proxyBeanMethods = false) @ConditionalOnBlockingDiscoveryEnabled @ConditionalOnPolarisDiscoveryEnabled -@AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class }) -@AutoConfigureAfter(PolarisDiscoveryAutoConfiguration.class) public class PolarisDiscoveryClientConfiguration { @Bean diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/reactive/PolarisReactiveDiscoveryClientConfiguration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/reactive/PolarisReactiveDiscoveryClientConfiguration.java index 47302b50c..0516de06a 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/reactive/PolarisReactiveDiscoveryClientConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/reactive/PolarisReactiveDiscoveryClientConfiguration.java @@ -17,18 +17,13 @@ package com.tencent.cloud.polaris.discovery.reactive; -import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration; import com.tencent.cloud.polaris.discovery.PolarisServiceDiscovery; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.client.ConditionalOnDiscoveryHealthIndicatorEnabled; import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled; -import org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration; -import org.springframework.cloud.client.discovery.composite.reactive.ReactiveCompositeDiscoveryClientAutoConfiguration; import org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIndicatorProperties; import org.springframework.cloud.client.discovery.health.reactive.ReactiveDiscoveryClientHealthIndicator; import org.springframework.context.annotation.Bean; @@ -42,8 +37,6 @@ @Configuration(proxyBeanMethods = false) @ConditionalOnReactiveDiscoveryEnabled @EnableConfigurationProperties(DiscoveryClientHealthIndicatorProperties.class) -@AutoConfigureAfter({PolarisDiscoveryAutoConfiguration.class, ReactiveCompositeDiscoveryClientAutoConfiguration.class}) -@AutoConfigureBefore({ReactiveCommonsClientAutoConfiguration.class}) public class PolarisReactiveDiscoveryClientConfiguration { @Bean From 7c5f3d1cff6c52c0b38e2d65341970b35903178d Mon Sep 17 00:00:00 2001 From: qingliu Date: Wed, 20 Sep 2023 10:57:32 +0800 Subject: [PATCH 2/2] fix: change the timing of sdk context destruction. (#1123) --- .../PolarisConfigAutoConfiguration.java | 7 ------ .../PolarisContextAutoConfiguration.java | 6 +++++ ...olarisContextApplicationEventListener.java | 23 ++++++------------- 3 files changed, 13 insertions(+), 23 deletions(-) rename spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigApplicationEventListener.java => spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/listener/PolarisContextApplicationEventListener.java (66%) diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java index 779e29751..b0c212a14 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java @@ -27,14 +27,12 @@ import com.tencent.cloud.polaris.config.annotation.PolarisConfigAnnotationProcessor; import com.tencent.cloud.polaris.config.condition.ConditionalOnReflectRefreshType; import com.tencent.cloud.polaris.config.config.PolarisConfigProperties; -import com.tencent.cloud.polaris.config.listener.PolarisConfigApplicationEventListener; import com.tencent.cloud.polaris.config.listener.PolarisConfigChangeEventListener; import com.tencent.cloud.polaris.config.listener.PolarisConfigRefreshOptimizationListener; import com.tencent.cloud.polaris.config.logger.PolarisConfigLoggerApplicationListener; import com.tencent.cloud.polaris.config.spring.annotation.SpringValueProcessor; import com.tencent.cloud.polaris.config.spring.property.PlaceholderHelper; import com.tencent.cloud.polaris.config.spring.property.SpringValueRegistry; -import com.tencent.cloud.polaris.context.PolarisSDKContextManager; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -122,10 +120,5 @@ public PolarisConfigRefreshScopeAnnotationDetector polarisConfigRefreshScopeAnno public PolarisConfigRefreshOptimizationListener polarisConfigRefreshOptimizationListener() { return new PolarisConfigRefreshOptimizationListener(); } - - @Bean - public PolarisConfigApplicationEventListener polarisContextApplicationEventListener(PolarisSDKContextManager polarisSDKContextManager) { - return new PolarisConfigApplicationEventListener(polarisSDKContextManager); - } } } diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextAutoConfiguration.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextAutoConfiguration.java index 1593fdd5f..080b0bf4f 100644 --- a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextAutoConfiguration.java +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextAutoConfiguration.java @@ -25,6 +25,7 @@ import com.tencent.cloud.polaris.context.PolarisConfigModifier; import com.tencent.cloud.polaris.context.PolarisSDKContextManager; import com.tencent.cloud.polaris.context.ServiceRuleManager; +import com.tencent.cloud.polaris.context.listener.PolarisContextApplicationEventListener; import com.tencent.polaris.api.exception.PolarisException; import com.tencent.polaris.client.api.SDKContext; @@ -58,4 +59,9 @@ public ModifyAddress polarisConfigModifier(PolarisContextProperties properties) public ServiceRuleManager serviceRuleManager(PolarisSDKContextManager polarisSDKContextManager) { return new ServiceRuleManager(polarisSDKContextManager.getSDKContext(), polarisSDKContextManager.getConsumerAPI()); } + + @Bean + public PolarisContextApplicationEventListener contextApplicationEventListener(PolarisSDKContextManager polarisSDKContextManager) { + return new PolarisContextApplicationEventListener(polarisSDKContextManager); + } } diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigApplicationEventListener.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/listener/PolarisContextApplicationEventListener.java similarity index 66% rename from spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigApplicationEventListener.java rename to spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/listener/PolarisContextApplicationEventListener.java index 68106382c..ae753045c 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigApplicationEventListener.java +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/listener/PolarisContextApplicationEventListener.java @@ -16,42 +16,33 @@ * */ -package com.tencent.cloud.polaris.config.listener; +package com.tencent.cloud.polaris.context.listener; import com.tencent.cloud.polaris.context.PolarisSDKContextManager; -import com.tencent.polaris.configuration.client.internal.RemoteConfigFileRepo; import org.springframework.boot.context.event.ApplicationFailedEvent; -import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.lang.NonNull; -/* - * Polaris config non-daemon thread stop listener - * - * @author shuiqingliu - * @since 2023/8/29 +/** + * @author frankjlli + * @since 2023/9/18 **/ -public class PolarisConfigApplicationEventListener implements ApplicationListener { + +public class PolarisContextApplicationEventListener implements ApplicationListener { private final PolarisSDKContextManager polarisSDKContextManager; - public PolarisConfigApplicationEventListener(PolarisSDKContextManager polarisSDKContextManager) { + public PolarisContextApplicationEventListener(PolarisSDKContextManager polarisSDKContextManager) { this.polarisSDKContextManager = polarisSDKContextManager; } @Override public void onApplicationEvent(@NonNull ApplicationEvent event) { - if (event instanceof ApplicationPreparedEvent) { - RemoteConfigFileRepo.registerRepoDestroyHook(polarisSDKContextManager.getSDKContext()); - } - if (event instanceof ApplicationFailedEvent) { - RemoteConfigFileRepo.registerRepoDestroyHook(polarisSDKContextManager.getSDKContext()); //implicit invoke 'destroy' when the spring application fails to start, in order to stop non-daemon threads. polarisSDKContextManager.getSDKContext().destroy(); } } - }