Skip to content

Commit

Permalink
refactor:optimize discovery properties initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyeBeFreeman committed Aug 2, 2023
1 parent 7f54dff commit 8f60cbd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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.
Expand All @@ -38,9 +37,26 @@
*/
@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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@ public void testDefaultInitialization() {
});
}

@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
Expand Down

0 comments on commit 8f60cbd

Please sign in to comment.