Skip to content
brentcrammond edited this page Dec 9, 2014 · 3 revisions

How to Integrate with JEE CDI

The following is how to integrate Owner with CDI.

Config.java

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.

ConfigProvider.java

import javax.enterprise.inject.Produces;
import org.aeonbits.owner.ConfigCache;
public class ConfigProvider {
    @Produces
    public Config getCore() {
        return ConfigCache.getOrCreate(Config.class);
    }
}

DataBean.java

@Named
public class DataBean {
    @Inject
    protected Config config;
    public String list() {
        return "Hello World: " + config.url();
    }
}
Clone this wiki locally