Configs Module

Features

Configs are a useful extension for properties files. It’s main features are:

  • Using a set of standard converters
  • Specifying default value for a property
  • Saving all properties that were used into file

You can add Boot module to your project by inserting a dependency in pom.xml:

<dependency>
    <groupId>io.datakernel</groupId>
    <artifactId>datakernel-config</artifactId>
    <version>3.1.0</version>
</dependency>

Example

Note: To run the example, you need to clone DataKernel from GitHub:
$ git clone https://github.com/softindex/datakernel
And import it as a Maven project. Check out branch v3.1. Before running the example, build the project.
These examples are located at datakernel -> examples -> core -> boot

An example of providing configs to your application:

public final class ConfigModuleExample {
	private static final String PROPERTIES_FILE = "example.properties";

	public static void main(String[] args) {
		Injector injector = Injector.of(Module.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));

		System.out.println(injector.getInstance(String.class));
		System.out.println(injector.getInstance(Integer.class));
		System.out.println(injector.getInstance(InetAddress.class));
	}
}