-
-
Notifications
You must be signed in to change notification settings - Fork 212
CDI Example
brentcrammond edited this page Dec 9, 2014
·
3 revisions
The following is how to integrate Owner with CDI.
import java.util.concurrent.TimeUnit;
import org.aeonbits.owner.Config.HotReload;
import org.aeonbits.owner.Config.HotReloadType;
import org.aeonbits.owner.Config.Sources;
@Sources({ "file:~/.data.config", "file:${jboss.server.data.dir}/data.properties", "classpath:data.properties" })
@HotReload(value = 1, unit = TimeUnit.MINUTES, type = HotReloadType.ASYNC)
public interface Config extends org.aeonbits.owner.Config {
@Key("office.url")
String url();
}
Note that we have used the WildFly variable ${jboss.server.data.dir} to specify the data directory. This is only appropriate for WildFly.
import javax.enterprise.inject.Produces;
import org.aeonbits.owner.ConfigCache;
public class ConfigProvider {
@Produces
public Config getCore() {
return ConfigCache.getOrCreate(Config.class);
}
}
@Named
public class DataBean {
@Inject
protected Config config;
public String list() {
return "Hello World: " + config.url();
}
}