The otj-config
component ties together a few configuration libraries.
commons-configuration is used to load configuration files from files or the classpath.
Supported URI schemes:
- file:///path/to/file
- classpath:/path/in/classpath
- empty:empty
config-magic takes the final configuration built from commons-configuration
and allows easy mapping on to Java objects.
otj-config
then provides helpers to bind configuration objects into a Guice Injector
.
public interface DemoConfig
{
@Config("ot.demo.greeting")
@Default("Hello, world!")
String getGreeting();
}
public class DemoConfigModule extends AbstractModule
{
@Override
public void configure()
{
// Bind a synthesized instance of DemoConfig
ConfigBinder.of(binder()).bind(DemoConfig.class);
}
}
public class DemoConfigUser
{
private final DemoConfig config;
@Inject
DemoConfigUser(DemoConfig config)
{
this.config = config;
}
public void getGreeting()
{
return config.getGreeting();
}
}
Foundation component
The configuration component is pulled in at a very early and delicate stage of service bootstrapping. It is crucial that the dependency footprint is minimal.
Copyright (C) 2014 OpenTable, Inc.