Skip to content

Latest commit

 

History

History
40 lines (32 loc) · 1.28 KB

README.md

File metadata and controls

40 lines (32 loc) · 1.28 KB

de.pa2.commons-configuration

This is our common used very slim API based configuration library.

usage

Examples can be found at https://github.com/pie-ai/pa-commons-configuration/tree/master/src/test/java/de/pa2/commons/configuration

Create a configuration interface:

public interface ExampleConfiguration extends Configuration {
	@DefaultBooleanValue(true)
	boolean isEnabledByDefault();

	@DefaultBooleanValue(false)
	boolean isNotEnabledByDefault();

	boolean isNotDefaultAnnotated();
}

Get an instance:

ExampleConfiguration cfg = ConfigurationFactory.getInstance(ExampleConfiguration.class);
assertThat(cfg.isEnabledByDefault()).isTrue();

Override configuration using System Properties:

System.setProperty("example.enabled.by.default", Boolean.FALSE.toString());
ExampleConfiguration cfg = ConfigurationFactory.getInstance(ExampleConfiguration.class);
assertThat(cfg.isEnabledByDefault()).isFalse();

Override configuration using Map:

Map<String, String> configuration = new HashMap<String, String>();
configuration.put("example.enabled.by.default", Boolean.FALSE.toString());
ExampleConfiguration cfg = ConfigurationFactory.getInstance(ExampleConfiguration.class, configuration);
assertThat(cfg.isEnabledByDefault()).isFalse();