Can we have @RefreshScope to refresh EnvironmentEndpoint bean at runtime
See original GitHub issueIn our application, we are creating EnvironmentEndpoint bean ourself as we need to override keysToSanitise.
We also want to refresh these keysToSanitise at run time when we have any update on property sources. So I have used @RefreshScope with it. But on application build I am getting below error:
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter@3c18b48e' method public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() to {[/env || /env.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}: There is already 'org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint@69e64aa8' bean method public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() mapped.
Below is my configuration:
@Configuration
@AutoConfigureBefore(EndpointAutoConfiguration.class)
@EnableConfigurationProperties(EndpointProperties.class)
public class EnvironmentEndpointAutoConfiguration {
private static final String SANITIZE_KEY_PREFIX = ".*";
@Bean
@RefreshScope
public EnvironmentEndpoint environmentEndpoint(ConfigurableEnvironment environment) {
EnvironmentEndpoint environmentEndpoint = new EnvironmentEndpoint();
final List<String> keysToSanitize = new ArrayList<>();
MutablePropertySources propertySources = environment.getPropertySources();
SystemEnvironmentPropertySource sampleSources = (SystemEnvironmentPropertySource) propertySources.get("sampleSources");
for (String name : sampleSources.getPropertyNames()) {
keysToSanitize.add(SANITIZE_KEY_PREFIX + name);
}
if (!keysToSanitize.isEmpty()) {
keysToSanitize.addAll(defaultKeysToSanitize("password", "secret", "key", "token", ".*credentials.*", "vcap_services"));
environmentEndpoint.setKeysToSanitize(keysToSanitize.toArray(new String[keysToSanitize.size()]));
}
return environmentEndpoint;
}
private List<String> defaultKeysToSanitize(String... keysToSanitize) {
List<String> keysList = new ArrayList<>();
for (int i = 0; i < keysToSanitize.length; i++) {
keysList.add(keysToSanitize[i]);
}
return keysList;
}
}
we are using spring boot 1.5.7 release version. I see some enhancement in spring boot 2.0 but that seems to be not released yet. We have external configuration using spring cloud consul to have refreshing of properties at runtime.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
EnvironmentEndpoint
is a boot thing, you’d need to go there to ask.As this is now being taken care in spring boot. I am closing this.