spring:
# 평문으로 소스 코드에 기재 가능한 경우
jackson:
date-format: yyyy-MM-dd'T'HH:mm:ss
# 민감 정보로 외부 저장소로 분리를 원하는 경우
datasource:
url: "{external/AAA}SPRING_DATASOURCE_URL"
username: "{external/AAA}SPRING_DATASOURCE_USERNAME"
password: "{external/AAA}SPRING_DATASOURCE_PASSWORD"public interface EnvironmentPostProcessor {
void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application);
} MutablePropertySources propertySources = environment.getPropertySources();
Map<String, Object> myMap = new HashMap<>();
myMap.put("xyz", "myValue");
propertySources.addFirst(new MapPropertySource("MY_MAP", myMap));custom.greeting: Hello world!@RequestMapping("/")
@RestController
public class HelloWorldController {
private final String greeting;
public HelloWorldController(@Value("${custom.greeting}") String greeting) {
this.greeting = greeting;
}
@GetMapping
public String helloWorld() {
return greeting;
}
}public class CsvEnvironmentPostProcessor implements EnvironmentPostProcessor {
public static final String CSV_ENVIRONMENT_FILE_PATH = "environment.csv.path";
public static final String PROPERTY_SOURCE_NAME = "csv";
public static final String CSV_DELIMITER = ",";
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
Map<String, Object> properties = readProperties(environment.getProperty(CSV_ENVIRONMENT_FILE_PATH));
environment.getPropertySources().addFirst(new MapPropertySource(PROPERTY_SOURCE_NAME, properties));
}
private Map<String, Object> readProperties(String filePath) {
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
return reader.lines()
.map(line -> line.split(CSV_DELIMITER))
.collect(Collectors.toUnmodifiableMap(elements -> elements[0], elements -> elements[1]));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}custom.greeting,Hello world(From CSV)environment.csv.path: ${실제 경로 입력}/resources/static/configuration.csv
custom.greeting: Hello world!org.springframework.boot.env.EnvironmentPostProcessor=com.ignite.configuration.CsvEnvironmentPostProcessorenvironment-providers:
csv:
path: /home/user/file1.csv
http:
url: https://some-storage.com/configuration/develop
aws:
secrets-manager:
name: a-project-productexport CUSTOM_GREETING="Hello world!(from os env)"{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue"
],
"Resource": "arn:aws:secretsmanager:${region}:${account-id}:secret:${secret-name}"
}
]
}CUSTOM_GREETING=$(aws secretsmanager get-secret-value --secret-id ${secret-name} --query SecretString --output text | jq -r ".${field name}")
export CUSTOM_GREETING
apiVersion: v1
kind: Pod
metadata:
name: secret-test-pod
spec:
containers:
- name: test-container
image: registry.k8s.io/busybox
command: [ "/bin/sh", "-c", "env" ]
envFrom:
- secretRef:
name: mysecret
restartPolicy: Never