cfg4j ("Configuration for Java") is a distributed apps-oriented configuration library for Java. It's very simple to use yet offers a comprehensive set of features:
- Distributed environment support:
- Runtime configuration reload (periodical, push and custom)
- Caching
- Support for multi-tenant configuration sources (e.g. keep configuration for all your environments [test, preprod, prod] in one store)
- Handle network failures (e.g. re-try, fallback to another source)
- Adapters for multiple configuration stores
- Git, Consul, ZooKeeper (WIP), MySQL (WIP), Files (YAML, Properties, XML)
- Easy yet flexible configuration management:
- Merge configurations from different sources
- Validation
- POJO configuration objects binding
- Modern design
- Extensible
- Well documented
- Heavily tested
- Dependency Injection-friendly
Explore the code of the sample apps.
Head to the documentation.
dependencies {
compile group: "org.cfg4j", name:"cfg4j", version: "3.1.0"
}
<dependencies>
<dependency>
<groupId>org.cfg4j</groupId>
<artifactId>cfg4j</artifactId>
<version>3.1.0</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:
- Use the following code in your application to connect to sample configuration source:
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) {
ConfigurationProvider configurationProvider =
ConfigurationProviders.backedByGit("https://github.com/cfg4j/cfg4j-git-sample-config.git");
SampleConfig config = configurationProvider.bind("reksio", SampleConfig.class);
// Use it!
System.out.println(config.homepage());
}
}
- Optional steps
- Fork the configuration sample repository.
- Add your configuration to the "application.properties" file and commit the changes.
- Update the code above to point to your fork.
Licensed under the Apache License, Version 2.0. See LICENSE file.