Skip to content
A simple configuration management library for any Java project!
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
src #77 Add test to ensure that numbers in the path are supported Feb 27, 2019
.checkstyle.xml Checkstyle: Require throws tag in Javadoc to be in sync with the java… Sep 9, 2018
.codeclimate.yml Exclude test classes in code climate config Aug 7, 2018
.editorconfig
.gitignore
.travis.yml
CHANGELOG.md Update docs after release Feb 27, 2019
LICENSE Create LICENSE Jul 8, 2016
README.md
pom.xml

README.md

ConfigMe

Build Status Coverage Status Javadocs Code Climate

A simple configuration management library with out of the box YAML support.

  • Lightweight
  • Flexible
  • Out of the box support for YAML
  • Allows migrations / config file checks
  • Null-safe
  • Unit testing friendly

How it works

  • Each configurable value is a Property in ConfigMe. Properties are declared as public static final fields in classes which implement the SettingsHolder interface.
  • Configurations are read from a PropertyResource (e.g. the provided YamlFileResource), which abstracts reading and writing.
  • The property resource may be checked for completeness with the MigrationService, which allows you also to move renamed properties or to remove obsolete ones.
  • The SettingsManager unifies the members above. On creation, it provokes a check by the migration service and allows the user to get property values from.

Integration

Start using ConfigMe by adding this to your pom.xml:

<dependencies>
    <dependency>
        <groupId>ch.jalu</groupId>
        <artifactId>configme</artifactId>
        <version>1.1.0</version>
    </dependency>
</dependencies>

Example

config.yml

title:
    text: 'Hello'
    size: 12

TitleConfig.java

public class TitleConfig implements SettingsHolder {

    public static final Property<String> TITLE_TEXT =
        newProperty("title.text", "-Default-");

    public static final Property<Integer> TITLE_SIZE =
        newProperty("title.size", 10);
    
    private TitleConfig() {
        // prevent instantiation
    }
}

WelcomeWriter.java

public class WelcomeWriter {
    public String generateWelcomeMessage() {
        SettingsManager settings = initSettings();
      
        // Get properties from the settings manager
        return "<font size=\"" 
            + settings.getProperty(TitleConfig.TITLE_SIZE) + "\">"
            + settings.getProperty(TitleConfig.TITLE_TEXT) + "</font>";
    }
  
    private SettingsManager initSettings() {
        // Create property resource
        PropertyResource resource = new YamlFileResource("config.yml");

        // Create migration service
        MigrationService migrationService = new PlainMigrationService();

        // Create settings manager
        return new SettingsManager(resource, migrationService, TitleConfig.class);
    }
}

📝 See a full working example based on this here.

📝 See how to use custom classes as property types in the bean properties demo.

You can’t perform that action at this time.