Spring Boot Customize Highest Priority Properties
this is useful for security-related configuration like password.
suppose in our spring-boot application, contains below config in yaml.
1 | app: |
the ${secret} is not refer to the real password, instead, it is a secret for fetching the real password from particular security platform.
so when we run our application, we first need to resolve the real password.
one elegant way would be:
define a
ApplicationListener
, and add to springApplication listeners.when the
Environment
prepared, implement the real password retrieve method by the provided secret.put into the first of the PropertySources list of this environment.
this can make sure each time, when we get secret
from environment, it will always return the first real password.
here is the code and output:
1 |
|
Title: Spring Boot Customize Highest Priority Properties
Author: mjd507
Date: 2022-07-24
Last Update: 2024-01-27
Blog Link: https://mjd507.github.io/2022/07/24/spring-boot-customize-highest-priority-properties/
Copyright Declaration: This station is mainly used to sort out incomprehensible knowledge. I have not fully mastered most of the content. Please refer carefully.