Skip to content

nirro01/konfi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Konfi - java properties library

build codecov Maven Central javadoc java

Main features

  • Clean type safe interface based properties
  • Optional values
  • Set and List collections
  • Refresh properties without restarting your app
  • Properties sources
    • OS environment variables
    • System properties
    • File packaged inside your jar (attached resources)
    • File outside your Jar
    • Custom source by implementing the Source interface

Getting started

  1. Add a dependency
Apache Maven
  <dependency>
    <groupId>io.github.nirro01</groupId>
    <artifactId>konfi-core</artifactId>
    <version>0.0.1</version>
  </dependency>
Gradle Groovy DSL
implementation 'io.github.nirro01:konfi-core:0.0.1'
Gradle Kotlin DSL
implementation("io.github.nirro01:konfi-core:0.0.1")
  1. Define your properties definitions using the @KonfiProperty annotation
public interface AmusementParkProperties {

    @KonfiProperty(key = "amusement.park.name", description = "Amusement park name")
    String name();
    
    @KonfiProperty(key = "amusement.park.phone-numbers", description = "Amusement park phone numbers")
    Set<String> phoneNumbers();
    
    @KonfiProperty(key = "amusement.park.email", description = "Amusement park email address")
    Optional<String> email();
    
    @KonfiProperty(key = "amusement.park.roller-coaster.minimum-height-cm", description = "Minimum height in centimeters for using the roller coaster")
    Integer rollerCoasterMinimumHeight();
    
    @KonfiProperty(key = "amusement.park.roller-coaster.active", description = "Roller coaster active")
    Boolean rollerCoasterActive();
}
  1. Define ordered list of properties sources
  var environmentVariablesSource = PropertiesSources.newEnvironmentVariablesSource();
  var systemPropertiesSource = PropertiesSources.newSystemPropertiesSource();
  var externalFileSource = PropertiesSources.newExternalFileSource("app.properties");
  var internalFileSource = PropertiesSources.newInternalFileSource("app.properties");
  var sources = List.of(environmentVariablesSource, systemPropertiesSource, externalFileSource, internalFileSource)
  1. Build instance of your interface
  AmusementParkProperties amusementParkProperties = Konfi
          .builder(AmusementParkProperties.class)
          .sources(sources)
          .build();
  String name = amusementParkProperties.name();
  System.out.println(name);
  1. Refresh properties on demand
  Konfi.refresh(amusementParkProperties);
  System.out.println(amusementParkProperties.name());

About

interface based properties for java

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages