- 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
- Add a dependency
<dependency>
<groupId>io.github.nirro01</groupId>
<artifactId>konfi-core</artifactId>
<version>0.0.1</version>
</dependency>
implementation 'io.github.nirro01:konfi-core:0.0.1'
implementation("io.github.nirro01:konfi-core:0.0.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();
}
- 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)
- Build instance of your interface
AmusementParkProperties amusementParkProperties = Konfi
.builder(AmusementParkProperties.class)
.sources(sources)
.build();
String name = amusementParkProperties.name();
System.out.println(name);
- Refresh properties on demand
Konfi.refresh(amusementParkProperties);
System.out.println(amusementParkProperties.name());