Git Product home page Git Product logo

cfg4j's Introduction

Twitter Follow Documentation Examples Maven Central JavaDoc GitHub license Travis

Overview

**cfg4j** ("Configuration for Java") is a **configuration library for Java distributed apps** (and not only).

Features:

  • Open source
  • Easy to use
  • Auto-reloads configuration
  • Powerful configuration mechanisms (interface binding, multi-source support with fallback strategy, merging, ...)
  • Distributed-environment friendly ( caching, support for multiple environments [test, preprod, prod], ...)
  • Reads configuration from: Consul, Git repos (YAML and/or properties), Files, Classpath, ...
  • Modern design
    • Seamless integration with DI containers: Spring, Guice and others
    • Exposes performance metrics by integration with Metrics library
    • Extensible (see the list of plugins below)
    • Heavily tested (99% code coverage)
    • Well documented
    • Java 7+ required

Usage

Read an article about configuration management using cfg4j.

Detailed documentation

Head to the documentation.

Sample apps

Explore the code of the sample apps.

Quick start

Setting up dependency

Gradle

dependencies {
  compile group: "org.cfg4j", name:"cfg4j-core", version: "4.4.0"
  
  // For Consul integration
  compile group: "org.cfg4j", name:"cfg4j-consul", version: "4.4.0"
  
  // For git integration
  compile group: "org.cfg4j", name:"cfg4j-git", version: "4.4.0"
}

Maven

<dependencies>
  <dependency>
    <groupId>org.cfg4j</groupId>
    <artifactId>cfg4j-core</artifactId>
    <version>4.4.0</version>
  </dependency>
  <!-- For Consul integration -->
  <dependency> 
    <groupId>org.cfg4j</groupId>
    <artifactId>cfg4j-consul</artifactId>
    <version>4.4.0</version>
  </dependency>
  <!-- For git integration -->
  <dependency>
    <groupId>org.cfg4j</groupId>
    <artifactId>cfg4j-git</artifactId>
    <version>4.4.0</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) {
    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());
  }

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

cfg4j's People

Contributors

buckett avatar fromanator avatar norbertpotocki avatar oshai avatar pimlock avatar ruslansennov avatar shudas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.