Modern configuration library for distributed apps written in Java.
cfg4j (“configuration for Java”) is a configuration library for Java distributed apps (and more).
Read an article about configuration management using cfg4j.
Head to the documentation.
Explore the code of the sample apps.
dependencies {
compile group: "org.cfg4j", name:"cfg4j-core", version: "4.4.1"
// For Consul integration
compile group: "org.cfg4j", name:"cfg4j-consul", version: "4.4.1"
// For git integration
compile group: "org.cfg4j", name:"cfg4j-git", version: "4.4.1"
}
<dependencies>
<dependency>
<groupId>org.cfg4j</groupId>
<artifactId>cfg4j-core</artifactId>
<version>4.4.1</version>
</dependency>
<!-- For Consul integration -->
<dependency>
<groupId>org.cfg4j</groupId>
<artifactId>cfg4j-consul</artifactId>
<version>4.4.1</version>
</dependency>
<!-- For git integration -->
<dependency>
<groupId>org.cfg4j</groupId>
<artifactId>cfg4j-git</artifactId>
<version>4.4.1</version>
</dependency>
</dependencies>
The fastest way to start working with cfg4j is to use a Git repository as a configuration store. To do that follow the steps:
public class Cfg4jPoweredApplication {
// Change this interface to whatever you want
public interface SampleConfig {
Integer birthYear();
List<String> friends();
URL homepage();
Map<String, Character> grades();
}
public static void main(String... args) {
ConfigurationSource source = new GitConfigurationSourceBuilder()
.withRepositoryURI("https://github.com/cfg4j/cfg4j-git-sample-config.git")
.build();
ConfigurationProvider provider = new ConfigurationProviderBuilder()
.withConfigurationSource(source)
.build();
SampleConfig config = configurationProvider.bind("reksio", SampleConfig.class);
// Use it!
System.out.println(config.homepage());
}
}
Licensed under the Apache License, Version 2.0. See LICENSE file.