Externalized Properties
A lightweight and extensible library to resolve application properties from various external sources.
Twelve Factor Methodology
Externalized Properties was inspired by the The Twelve Factor Methodology's section III. Config.
The goal of this library is to make it easy for applications to implement configuration best practices by providing easy-to-use APIs as well as providing the flexibility to choose where to store their configurations/properties.
🛠️
Installation
Gradle
implementation "io.github.joeljeremy7.externalizedproperties:core:${version}"
Maven
<dependency>
<groupId>io.github.joeljeremy7.externalizedproperties</groupId>
<artifactId>core</artifactId>
<version>${version}</version>
</dependency>
🧩
Java 9 Module Names
Externalized Properties jars are published with Automatic-Module-Name manifest attribute:
- Core -
io.github.joeljeremy7.externalizedproperties.core
- Database Resolver -
io.github.joeljeremy7.externalizedproperties.resolvers.database
Module authors can use above module names in their module-info.java:
module foo.bar {
requires io.github.joeljeremy7.externalizedproperties.core;
requires io.github.joeljeremy7.externalizedproperties.resolvers.database;
}
🌟
Features
🔗
Property Resolution via Java Dynamic Proxies (Why Dynamic Proxies?)
🔗
Conversion
🔗
Variable Expansion
🔗
Processing
🔗
Profiles
🔗
Ordinal Components
🏎️
Quick Start
Properties are mapped to proxy interface methods by using the @ExternalizedProperty annotation.
(For more advanced scenarios, please see the feature documentations.)
Given an interface:
public interface ApplicationProperties {
@ExternalizedProperty("java.home")
String javaHome();
@ExternalizedProperty("encrypted.property")
@Decrypt("MyDecryptor")
String encryptedProperty();
@ExternalizedProperty("java.version")
int javaVersion();
}
We can initialize and start resolving external configurations/properties by:
public static void main(String[] args) {
// 1. Configure and build the ExternalizedProperties instance.
ExternalizedProperties externalizedProperties = buildExternalizedProperties();
// 2. Initialize a proxy using the ExternalizedProperties.
ApplicationProperties props = externalizedProperties.initialize(ApplicationProperties.class);
// 3. Resolve the properties.
String javaHome = props.javaHome();
String encryptedProperty = props.encryptedProperty();
int javaVersion = props.javaVersion();
}
private static ExternalizedProperties buildExternalizedProperties() {
return ExternalizedProperties.builder()
.defaults()
.resolvers(...)
.processors(...)
.converters(...)
.build();
}
🧪
Samples
More sample can be found here: https://github.com/joeljeremy7/externalized-properties-samples