Skip to content

Instantly share code, notes, and snippets.

@struberg
Created January 17, 2017 10:58
Show Gist options
  • Save struberg/77f710b013a9b0e62048b1620040d77a to your computer and use it in GitHub Desktop.
Save struberg/77f710b013a9b0e62048b1620040d77a to your computer and use it in GitHub Desktop.
@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