https://github.com/joel-jeremy/externalized-properties
A lightweight and extensible library to resolve application properties from various external sources.
https://github.com/joel-jeremy/externalized-properties
configuration feature-flags feature-toggles java jvm properties
Last synced: 7 months ago
JSON representation
A lightweight and extensible library to resolve application properties from various external sources.
- Host: GitHub
- URL: https://github.com/joel-jeremy/externalized-properties
- Owner: joel-jeremy
- License: apache-2.0
- Created: 2021-10-29T19:04:28.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-23T01:49:13.000Z (about 1 year ago)
- Last Synced: 2024-11-08T17:47:42.935Z (12 months ago)
- Topics: configuration, feature-flags, feature-toggles, java, jvm, properties
- Language: Java
- Homepage:
- Size: 1.46 MB
- Stars: 27
- Watchers: 3
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-java-zh - Externalized Properties - 轻量级但功能强大的配置库,支持从外部源和可扩展的后处理/转换机制的属性的分辨率。 (项目 / 配置)
- awesome-java - Externalized Properties - Lightweight yet powerful configuration library which supports resolution of properties from external sources and an extensible post-processing/conversion mechanism. (Projects / Configuration)
- fucking-awesome-java - Externalized Properties - Lightweight yet powerful configuration library which supports resolution of properties from external sources and an extensible post-processing/conversion mechanism. (Projects / Configuration)
README
# Externalized Properties
[](https://github.com/joel-jeremy/externalized-properties/blob/main/LICENSE)
[](https://github.com/joel-jeremy/externalized-properties/actions/workflows/gradle-build.yaml)
[](https://github.com/joel-jeremy/externalized-properties/actions/workflows/codeql.yaml)
[](https://search.maven.org/search?q=g:%22io.github.joel-jeremy.externalized-properties%22)
[](https://coveralls.io/github/joel-jeremy/externalized-properties?branch=main)
[](https://sonarcloud.io/summary/new_code?id=io.github.joel-jeremy.externalized-properties)
[](https://sonarcloud.io/summary/new_code?id=io.github.joel-jeremy.externalized-properties)
[](https://sonarcloud.io/summary/new_code?id=io.github.joel-jeremy.externalized-properties)
[](https://sonarcloud.io/summary/new_code?id=io.github.joel-jeremy.externalized-properties)
[](https://sonarcloud.io/summary/new_code?id=io.github.joel-jeremy.externalized-properties)
[](https://sonarcloud.io/summary/new_code?id=io.github.joel-jeremy.externalized-properties)
[](https://discord.gg/SVfahQGMmx)
A lightweight and extensible library to resolve application properties from various external sources.
## Like the project?
Please consider giving the repository a ⭐. It means a lot! Thank you :)
## [Twelve Factor Methodology](https://12factor.net)
Externalized Properties was inspired by the [The Twelve Factor Methodology](https://12factor.net)'s section [III. Config](https://12factor.net/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
```groovy
implementation "io.github.joel-jeremy.externalized-properties:externalized-properties-core:${version}"
// Optional/additional resolvers
implementation "io.github.joel-jeremy.externalized-properties:externalized-properties-database:${version}"
implementation "io.github.joel-jeremy.externalized-properties:externalized-properties-git:${version}"
```
### Maven
```xml
io.github.joel-jeremy.externalized-properties
externalized-properties-core
${version}
io.github.joel-jeremy.externalized-properties
externalized-properties-database
${version}
io.github.joel-jeremy.externalized-properties
externalized-properties-git
${version}
```
### 🧩 Java 9 Module Names
Externalized Properties jars are published with Automatic-Module-Name manifest attribute:
- Core - `io.github.joeljeremy.externalizedproperties.core`
- Database Resolver - `io.github.joeljeremy.externalizedproperties.database`
- Git Resolver - `io.github.joeljeremy.externalizedproperties.git`
Module authors can use above module names in their module-info.java:
```java
module foo.bar {
requires io.github.joeljeremy.externalizedproperties.core;
requires io.github.joeljeremy.externalizedproperties.database;
requires io.github.joeljeremy.externalizedproperties.git;
}
```
## 🌟 Features
Externalized Properties takes full advantage of Java's [Dynamic Proxies](https://docs.oracle.com/javase/8/docs/technotes/guides/reflection/proxy.html) ([Why Dynamic Proxies?](docs/why-dynamic-proxies.md)).
### ✔️ Property Resolution
- [Map Properties to (Java Dynamic Proxy) Interface Methods](docs/property-resolution.md#-map-properties-to-java-dynamic-proxy-interface-methods)
- [Default/Fallback Values](docs/property-resolution.md#-defaultfallback-values)
- [Support for Property Names Known at Runtime](docs/property-resolution.md#-support-for-property-names-known-at-runtime)
- [Support for Various Configuration File/Resource Formats](docs/property-resolution.md#-support-for-various-configuration-fileresource-formats)
- [Caching](docs/property-resolution.md#-caching)
- [Eager Loading](docs/property-resolution.md#-eager-loading)
- [Custom Resolvers](docs/property-resolution.md#-custom-resolvers)
### ✔️ Conversion
- [Automatic Property Conversion](docs/conversion.md#-automatic-property-conversion)
- [Conversion to Generic Types](docs/conversion.md#-conversion-to-generic-types)
- [Conversion of Arbitrary Values](docs/conversion.md#-conversion-of-arbitrary-values)
- [Custom Converters](docs/conversion.md#-custom-converters)
### ✔️ Variable Expansion
- [Automatic Variable Expansion in Property Names](docs/variable-expansion.md#-automatic-variable-expansion-in-property-names)
- [Automatic Variable Expansion in Properties](docs/variable-expansion.md#-automatic-variable-expansion-in-properties)
- [Variable Expansion in Arbitrary Values](docs/variable-expansion.md#-variable-expansion-in-arbitrary-values)
### ✔️ Processing
- [Targeted Processing of Properties](docs/processing.md#-targeted-processing-of-properties)
- [Custom Processors](docs/processing.md#-custom-processors)
### ✔️ Profiles
- [Profile-Specific Configurations](docs/profiles.md#-profile-specific-configurations)
### ✔️ Ordinal Components
- [Ordinal Resolvers](docs/ordinal-components.md#-ordinal-resolvers)
- [Ordinal Converters](docs/ordinal-components.md#-ordinal-converters)
## 🏎️ Quick Start
Properties are mapped to proxy interface methods by using the [@ExternalizedProperty](core/src/main/java/io/github/joeljeremy/externalizedproperties/core/ExternalizedProperty.java) annotation.
(For more advanced scenarios, please see the feature documentations.)
Given an interface:
```java
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:
```java
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: