Coder Social home page Coder Social logo

meiblorn / confij Goto Github PK

View Code? Open in Web Editor NEW

This project forked from keykey7/confij

0.0 0.0 0.0 862 KB

ConfiJ is a Java configuration framework to facilitate loading and validating configurations from various sources in a type-safe manner.

License: Apache License 2.0

Java 100.00%

confij's Introduction

ConfiJ - Configuration for Java

Build Status License Coverage Maven Central

See the full documentation at https://keykey7.github.io/confij/

ConfiJ Logo

ConfiJ is a Java configuration framework to facilitate loading and validating configurations from various sources in a type-safe manner. This includes features such as:

  • configuration definition as interfaces
  • even as lists/maps/arrays/... of nested configurations
  • support for various source formats: properties, YAML, HOCON, JSON, TOML
  • load from various sources at once with different merge strategies
  • load from: git, file, classpath, system properties, environment variables
  • binding support to various immutable property types like URL, DateTime, Duration, enums, Period,...
  • templating support (variable substitutions), even within paths
  • plugin support for more formats and sources
  • from simple non-null validation to powerful JSR303 bean validation
  • live reloading hooks for change detection
  • no external dependencies required by the core package

Example

Define your configuration in code:

interface HouseConfiguration {     // configuration definition as interfaces (or any)
    boolean hasRoof();             // bind to primitives
    LocalDate constructedAt();     // ...or to complex types, like temporal ones
    Room livingRoom();             // nested configurations
    Map<String, Room> rooms();     // ...even in Maps (usually immutable)
    Set<String> inhabitants();     // ...or Collections, Arrays
}
@NotNull                           // enforce well defined values (recursive)
interface Room {                   // nested definition
    @Default("1")                  // defaults and other customizations
    @Positive                      // optional full JSR303 bean validation
    int numberOfDoors();           // will become 1 if not defined otherwise
                                   //
    @Default("${numberOfDoors}")   // templating support: referencing other keys
    Optional<Integer> lockCount(); // explicit optionals
}

Load it as flexible as you need it (but always fail fast on unknown values):

HouseConfiguration johnsHouse = ConfijBuilder.of(HouseConfiguration.class)
    .loadFrom("classpath:house.properties")   // first read properties from classpath 
    .loadFrom("johnshouse.yaml")              // override with a YAML file on disk
    .loadOptionalFrom("*-test.${sys:ending}") // wildcards, variables, optional,...
    .loadFrom(EnvvarSource.withPrefix("APP")) // then read EnvVars like APP_hasRoof=true
    .build();                                 // build an immutable instance
# sample johnshouse.yaml
hasRoof: yes
constructedAt: 2000-12-24
livingRoom:
  numberOfDoors: 4
  lockCount: 1
rooms:
  bathRoom: {}
  kitchen:
    numberOfDoors: 2
inhabitants:
  - John
  - Alice

See the full documentation at https://keykey7.github.io/confij/

-- ☕⚙️

confij's People

Contributors

keykey7 avatar syhily 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.