Inject Environment into health indicator
Fixes gh-457, fixes gh-456
This commit is contained in:
committed by
Dave Syer
parent
3caa7cda0d
commit
8feec99600
@@ -34,6 +34,7 @@ import org.springframework.core.env.Environment;
|
||||
* the config server, if there is one.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Marcos Barbero
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
@@ -60,8 +61,8 @@ public class ConfigClientAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public ConfigServerHealthIndicator configServerHealthIndicator(
|
||||
ConfigServicePropertySourceLocator locator) {
|
||||
return new ConfigServerHealthIndicator(locator);
|
||||
ConfigServicePropertySourceLocator locator, Environment environment) {
|
||||
return new ConfigServerHealthIndicator(locator, environment);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,32 +5,28 @@ import java.util.List;
|
||||
|
||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.Health.Builder;
|
||||
import org.springframework.core.env.AbstractEnvironment;
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Marcos Barbero
|
||||
*/
|
||||
public class ConfigServerHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
private ConfigServicePropertySourceLocator locator;
|
||||
private Environment env;
|
||||
private ConfigServicePropertySourceLocator locator;
|
||||
private Environment environment;
|
||||
|
||||
public ConfigServerHealthIndicator(ConfigServicePropertySourceLocator locator) {
|
||||
this.env = new AbstractEnvironment() {
|
||||
@Override
|
||||
public String[] getActiveProfiles() {
|
||||
return new String[] {"default"};
|
||||
}
|
||||
};
|
||||
this.locator = locator;
|
||||
}
|
||||
public ConfigServerHealthIndicator(ConfigServicePropertySourceLocator locator,
|
||||
Environment environment) {
|
||||
this.environment = environment;
|
||||
this.locator = locator;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHealthCheck(Builder builder) throws Exception {
|
||||
PropertySource<?> propertySource = locator.locate(this.env);
|
||||
PropertySource<?> propertySource = locator.locate(this.environment);
|
||||
builder.up();
|
||||
if (propertySource instanceof CompositePropertySource) {
|
||||
List<String> sources = new ArrayList<>();
|
||||
|
||||
@@ -29,14 +29,16 @@ import org.springframework.core.env.PropertySource;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Marcos Barbero
|
||||
*
|
||||
*/
|
||||
public class ConfigServerHealthIndicatorTests {
|
||||
|
||||
private ConfigServicePropertySourceLocator locator = Mockito
|
||||
.mock(ConfigServicePropertySourceLocator.class);
|
||||
private Environment environment = Mockito.mock(Environment.class);
|
||||
private ConfigServerHealthIndicator indicator = new ConfigServerHealthIndicator(
|
||||
locator);
|
||||
locator, environment);
|
||||
|
||||
@Test
|
||||
public void testDefaultStatus() {
|
||||
|
||||
Reference in New Issue
Block a user