refactor:optimize discovery properties initialization. (#1077)

pull/1086/head
Haotian Zhang 1 year ago committed by GitHub
parent 654750ed58
commit 043fcb4be8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -24,3 +24,4 @@
- [fix:fix router label feign interceptor order.](https://github.com/Tencent/spring-cloud-tencent/pull/1069)
- [feat:added polaris weighted round robin load balancer.](https://github.com/Tencent/spring-cloud-tencent/pull/1062)
- [fix:add deregister judgment.](https://github.com/Tencent/spring-cloud-tencent/pull/1074)
- [refactor:optimize discovery properties initialization.](https://github.com/Tencent/spring-cloud-tencent/pull/1077)

@ -29,7 +29,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* Common configuration of discovery.
@ -38,9 +37,26 @@ import org.springframework.context.annotation.Import;
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnPolarisEnabled
@Import({PolarisDiscoveryProperties.class, ConsulContextProperties.class, NacosContextProperties.class})
public class DiscoveryPropertiesAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public PolarisDiscoveryProperties polarisDiscoveryProperties() {
return new PolarisDiscoveryProperties();
}
@Bean
@ConditionalOnMissingBean
public ConsulContextProperties consulContextProperties() {
return new ConsulContextProperties();
}
@Bean
@ConditionalOnMissingBean
public NacosContextProperties nacosContextProperties() {
return new NacosContextProperties();
}
@Bean
@ConditionalOnMissingBean
public PolarisDiscoveryHandler polarisDiscoveryHandler(PolarisDiscoveryProperties polarisDiscoveryProperties,

@ -24,8 +24,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
@ -50,36 +48,4 @@ public class DiscoveryPropertiesAutoConfigurationTest {
assertThat(context).hasSingleBean(DiscoveryConfigModifier.class);
});
}
@Test
public void testInit() {
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner().withConfiguration(
AutoConfigurations.of(
PolarisContextAutoConfiguration.class,
TestConfiguration.class,
DiscoveryPropertiesAutoConfiguration.class))
.withPropertyValues("spring.cloud.polaris.discovery.register=false")
.withPropertyValues("spring.cloud.consul.discovery.register=false")
.withPropertyValues("spring.cloud.consul.discovery.enabled=false");
applicationContextRunner.run(context -> {
assertThat(context).hasSingleBean(DiscoveryPropertiesAutoConfiguration.class);
});
}
@Configuration
static class TestConfiguration {
@Bean
public PolarisDiscoveryProperties polarisDiscoveryProperties() {
PolarisDiscoveryProperties polarisDiscoveryProperties = new PolarisDiscoveryProperties();
polarisDiscoveryProperties.setEnabled(false);
return polarisDiscoveryProperties;
}
@Bean
public ConsulContextProperties consulContextProperties() {
ConsulContextProperties consulContextProperties = new ConsulContextProperties();
consulContextProperties.setEnabled(true);
return consulContextProperties;
}
}
}

Loading…
Cancel
Save