This project provides Spring utility code.
This module provides a custom Spring Boot property source that allows for integration of secrets into your application's configuration.
- Add the
caf-propertysource-spring
dependency to your project:
<dependency>
<groupId>com.github.cafapi.util.spring</groupId>
<artifactId>caf-propertysource-spring</artifactId>
<version>VERSION</version>
</dependency>
- Register the
CafConfigEnvironmentListener
:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(MyApplication.class);
app.addListeners(new CafConfigEnvironmentListener()); // Register the listener
app.run(args);
}
}
- In your
application.properties
orapplication.yaml
, you can now use thesecret:
prefix to reference secrets:
my.secret.property: ${secret:MY_SECRET_KEY}
my.secret.with.default: ${secret:ANOTHER_SECRET_KEY:defaultValue}
The secrets will be automatically resolved during application startup.