Last active
May 30, 2021 10:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/sterlp/training/tree/master/spring-hystrix