Skip to content

conf4j/conf4j

Repository files navigation

Configuration 4 Java

Build Status Coverage Status Maven Central

Installation

Gradle

compile 'org.conf4j:conf4j-core:2018.10.1'

Maven

<dependency>
  <groupId>org.conf4j</groupId>
  <artifactId>conf4j-core</artifactId>
  <version>2018.10.1</version>
</dependency>

Usage

Getting Started

  1. Add conf4j dependency to your project
  2. Build your configuration provider using ConfigurationProviderBuilder
  3. Get an instance of your config bean from the configuration provider
public class Main {
  public static void main(String[] args) throws Exception {
    ConsulFileConfigurationSource prodConfigSource = ConsulFileConfigurationSource.builder()
        .withConfigurationFilePath("prod/test-service.conf")
        .withConsulUrl("localhost:8500")
        .reloadOnChange()
        .build();

    ClasspathConfigurationSource fallbackConfigSource = ClasspathConfigurationSource.builder()
        .withResourcePath("fallback.conf")
        .build();

    ConfigurationProvider<TestConfigBean> provider = new ConfigurationProviderBuilder<>(TestConfigBean.class)
        .withConfigurationSource(prodConfigSource)
        .addFallback(fallbackConfigSource)
        .build();

    provider.registerChangeListener((oldConfig, newConfig) -> myListener(newConfig));
    TestConfigBean config = provider.get();
  }
}

Contribution

  • Fork
  • Code
  • ./mvnw test
  • Issue a PR :)