Lightweight Java Configuration Management
Small, simple and lightweight java framework to manage configurations
<dependency>
<groupId>io.github.leberkleber.ljcm</groupId>
<artifactId>ljcm-minimal</artifactId>
<version>1.0.1</version>
</dependency>
public class Configuration {
@Configuration("my.config.key")
private String myConfig;
public String getMyConfig() {
return myConfig;
}
}
public static void main(String[] args){
ConfigurationProcessor cp = new ConfigurationProcessorBuilder()
.addConfigurationParsers(Parser.getDefaultParser())
.setConfigurationLoader(
new HierarchicalLoader.Builder()
.addLoader(new EnvironmentVariableLoader())
.addLoader(new PropertiesFileLoader("classpath:/app.properties"))
.addLoader(new PropertiesFileLoader("/etc/myapp/app.properties"))
.build();
).build();
cp.process(Configuration.class);
}
The "ljcm-minimal-parser" contains a minial set of parsers:
- Boolean / boolean @BooleanParser
- Byte / byte @ByteParser
- Character[] / char[] @CharArrayParser
- Character / char @CharParser
- Double / double @DoubleParser
- Float / float @FloatParser
- Integer / int @IntParser
- Long / long @LongParser
- Short / short @ShortParser
- String @ StringParser
All "minimal-parser" can be loaded via:
Parser.getDefaultParser()
A custom parser must implement the "ConfigurationParser" interface.
The "ljcm-minimal-loader" contains a minial set of loaders:
- HierarchicalLoader
- EnvironmentVariableLoader
- PropertiesFileLoader
ljcm uses jul. You can easy use a jul-bridge e.g.: SLF4J:
import java.util.logging.Logger;
import org.slf4j.bridge.SLF4JBridgeHandler;
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();