Config
Overview
Config is a useful tool for configuring application components. It can collect provided configuration from files, class path, system properties, etc. The configuration can then be transformed, overwritten, logged in the runtime.
Features
- Using a set of standard data converters to/from a config
- Ability to specify default values for properties
- Ability to save all used properties into a file
Example
note
To run the examples, you need to clone ActiveJ from GitHub
git clone https://github.com/activej/activej
And import it as a Maven project. Check out tag v6.0-beta2. Before running the examples, build the project.
These examples are located at activej/examples/core/boot
An example of providing configs to your application with Config
public final class ConfigModuleExample {
private static final String PROPERTIES_FILE = "example.properties";
public static void main(String[] args) {
Injector injector = Injector.of(ModuleBuilder.create()
.bind(Config.class).to(() -> Config.ofClassPathProperties(PROPERTIES_FILE))
.bind(String.class).to(c -> c.get("phrase"), Config.class)
.bind(Integer.class).to(c -> c.get(ofInteger(), "number"), Config.class)
.bind(InetAddress.class).to(c -> c.get(ofInetAddress(), "address"), Config.class)
.build());
System.out.println(injector.getInstance(String.class));
System.out.println(injector.getInstance(Integer.class));
System.out.println(injector.getInstance(InetAddress.class));
}
}