Skip to content

Latest commit

 

History

History
90 lines (75 loc) · 3.26 KB

README.md

File metadata and controls

90 lines (75 loc) · 3.26 KB

GitHub license Maven Central Travis Documentation Examples JavaDoc

Overview

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
  • 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

Usage

Sample apps

Explore the code of the sample apps.

Detailed documentation

Head to the documentation.

Quick start

Setting up dependency

Gradle

dependencies {
  compile group: "org.cfg4j", name:"cfg4j", version: "3.3.1"
}

Maven

<dependencies>
  <dependency>
    <groupId>org.cfg4j</groupId>
    <artifactId>cfg4j</artifactId>
    <version>3.3.1</version>
  </dependency>
</dependencies>

Usage

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
    1. Fork the configuration sample repository.
    2. Add your configuration to the "application.properties" file and commit the changes.
    3. Update the code above to point to your fork.

License

Licensed under the Apache License, Version 2.0. See LICENSE file.