Ensures HikariDataSource is never re-bound.

Removes HikariDataSource from extra-refreshable and adds it to a new property never-refreshable.

ConfigurationPropertiesRebinder now checks that property and does not rebind beans whose class is in never-refreshable.

fixes gh-687
This commit is contained in:
Spencer Gibb
2020-03-03 17:54:58 -05:00
parent 5ea26e13a3
commit 69a8cece5f
5 changed files with 68 additions and 14 deletions

View File

@@ -16,6 +16,8 @@
package org.springframework.cloud.autoconfigure;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Rule;
import org.junit.Test;
@@ -30,6 +32,7 @@ import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.BDDAssertions.then;
/**
@@ -68,8 +71,9 @@ public class RefreshAutoConfigurationTests {
public void refreshables() {
try (ConfigurableApplicationContext context = getApplicationContext(
WebApplicationType.NONE, Config.class, "config.foo=bar",
"spring.cloud.refresh.refreshable:" + ConfigProps.class.getName())) {
context.getBean(ConfigProps.class);
"spring.cloud.refresh.refreshable:"
+ SealedConfigProps.class.getName())) {
context.getBean(SealedConfigProps.class);
context.getBean(ContextRefresher.class).refresh();
}
}
@@ -77,23 +81,37 @@ public class RefreshAutoConfigurationTests {
@Test
public void extraRefreshables() {
try (ConfigurableApplicationContext context = getApplicationContext(
WebApplicationType.NONE, Config.class, "config.foo=bar",
WebApplicationType.NONE, Config.class, "sealedconfig.foo=bar",
"spring.cloud.refresh.extra-refreshable:"
+ ConfigProps.class.getName())) {
context.getBean(ConfigProps.class);
+ SealedConfigProps.class.getName())) {
context.getBean(SealedConfigProps.class);
context.getBean(ContextRefresher.class).refresh();
}
}
@Test
public void neverRefreshable() {
try (ConfigurableApplicationContext context = getApplicationContext(
WebApplicationType.NONE, Config.class, "countingconfig.foo=bar",
"spring.cloud.refresh.never-refreshable:"
+ CountingConfigProps.class.getName())) {
CountingConfigProps configProps = context.getBean(CountingConfigProps.class);
context.getBean(ContextRefresher.class).refresh();
assertThat(configProps.count)
.as("config props was rebound when it should not have been")
.hasValue(1);
}
}
@Configuration(proxyBeanMethods = false)
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
@EnableConfigurationProperties(ConfigProps.class)
@EnableConfigurationProperties({ SealedConfigProps.class, CountingConfigProps.class })
static class Config {
}
@ConfigurationProperties("config")
static class ConfigProps {
@ConfigurationProperties("sealedconfig")
static class SealedConfigProps {
private String foo;
@@ -113,4 +131,22 @@ public class RefreshAutoConfigurationTests {
}
@ConfigurationProperties("countingconfig")
static class CountingConfigProps {
private final AtomicInteger count = new AtomicInteger();
private String foo;
public String getFoo() {
return this.foo;
}
public void setFoo(String foo) {
count.incrementAndGet();
this.foo = foo;
}
}
}