Created
January 17, 2017 10:58
-
-
Save struberg/77f710b013a9b0e62048b1620040d77a to your computer and use it in GitHub Desktop.
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
@ApplicationScoped | |
public class DynamicConfigUsageSample { | |
private @Inject Config config; | |
private ConfigValue<String> serverUrlCfg; | |
private ConfigValue<Integer> serverPortCfg | |
@PostConstruct | |
private void init() { | |
serverUrlCfg= config.access("com.acme.myproject.someserver.url") | |
.cacheFor(5, TimeUnit.MINUTES) | |
.logChanges(true) | |
.evaluateVariables(true); | |
serverPortCfg = config.access("com.acme.myproject.someserver.port") | |
.as(Integer.class) | |
.cacheFor(5, TimeUnit.MINUTES) | |
.logChanges(true) | |
.evaluateVariables(true) | |
.withDefault(8080); | |
} | |
public void useTheConfig() { | |
callToServer(serverUrlCfg.getValue(), serverPortCfg.getValue()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment