Skip to content

Instantly share code, notes, and snippets.

@sterlp
Last active May 30, 2021 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sterlp/8f1a3c4effd2108aad1b345ee0c84c0d to your computer and use it in GitHub Desktop.
Save sterlp/8f1a3c4effd2108aad1b345ee0c84c0d to your computer and use it in GitHub Desktop.
List spring boot configuration and configure Hystrix using application.properties instead of config.properties
@Configuration
public class HystrixConfig {
@Autowired
private Environment env;
@EventListener({
ContextRefreshedEvent.class, // on spring start
EnvironmentChangeEvent.class // on configuration changes, requires spring-cloud
}
)
public void onRefresh(ApplicationContextEvent event) {
final MutablePropertySources mps = ((AbstractEnvironment)this.env).getPropertySources();
StreamSupport.stream(mps.spliterator(), false)
.filter(ps -> ps instanceof EnumerablePropertySource)
.map(ps -> ((EnumerablePropertySource<?>)ps).getPropertyNames())
.flatMap(Arrays::<String>stream)
.filter(ps -> ps.startsWith("hystrix."))
.forEach(propName -> {
ConfigurationManager.getConfigInstance().setProperty(propName, this.env.getProperty(propName));
// System.err.println(propName + "\t= " + this.env.getProperty(propName));
});
}
// more config
}
@sterlp
Copy link
Author

sterlp commented May 30, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment