Skip to content

Commit

Permalink
Allow refresh auto config to be disabled by property.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed Nov 29, 2017
1 parent 4675df3 commit 259aa43
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.cloud.context.environment.EnvironmentManager;
import org.springframework.cloud.context.refresh.ContextRefresher;
Expand All @@ -47,6 +48,7 @@
*/
@Configuration
@ConditionalOnClass(RefreshScope.class)
@ConditionalOnProperty(name = "spring.cloud.refresh.enabled", matchIfMissing = true)
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
public class RefreshAutoConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@
*/
@Configuration
@ConditionalOnClass(Endpoint.class)
@AutoConfigureAfter(EndpointAutoConfiguration.class)
@AutoConfigureAfter({EndpointAutoConfiguration.class, RefreshAutoConfiguration.class})
public class RefreshEndpointAutoConfiguration {

@Bean
@ConditionalOnBean(RefreshScope.class)
@ConditionalOnMissingBean
@ConditionalOnEnabledHealthIndicator("refresh")
@Bean
RefreshScopeHealthIndicator refreshScopeHealthIndicator(RefreshScope scope,
ConfigurationPropertiesRebinder rebinder) {
return new RefreshScopeHealthIndicator(scope, rebinder);
Expand Down Expand Up @@ -113,6 +114,7 @@ public RestartEndpoint.ResumeEndpoint resumeEndpoint(
protected static class RefreshEndpointConfiguration {

@Bean
@ConditionalOnBean(ContextRefresher.class)
@ConditionalOnMissingBean
public RefreshEndpoint refreshEndpoint(ContextRefresher contextRefresher) {
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;


/**
* @author Dave Syer
Expand All @@ -26,8 +24,16 @@ public class RefreshAutoConfigurationTests {
public void noWarnings() {
try (ConfigurableApplicationContext context = getApplicationContext(
Config.class)) {
assertTrue(context.containsBean("refreshScope"));
assertThat(output.toString(), not(containsString("WARN")));
assertThat(context.containsBean("refreshScope")).isTrue();
assertThat(output.toString()).doesNotContain("WARN");
}
}

@Test
public void disabled() {
try (ConfigurableApplicationContext context = getApplicationContext(
Config.class, "spring.cloud.refresh.enabled:false")) {
assertThat(context.containsBean("refreshScope")).isFalse();
}
}

Expand Down

0 comments on commit 259aa43

Please sign in to comment.