【发布时间】:2024-01-18 10:55:01
【问题描述】:
从外部 secrets.txt 中获取用户名/密码属性到 app.yaml 中的 DB2 数据源:spring boot
Java 文件:
@PropertySource(factory = YamlPropertySourceFactory.class, value = "${secrets.filepath}")
public class XyzApplication extends SpringBootServletInitializer {
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
App.yml:
secrets:
filepath: file:src/main/resources/secrets/secret.txt
Spring:
datasource:
url: jdbc:some db conn path
username: username (??)
password: password (??)
Secrets.txt
spring.datasource.username: abcd
spring.datasource.password: p@ssWord
但是用户名、密码没有从 secret.txt 中选择到 app.yml
请提出任何更正或替代方法
【问题讨论】:
-
如果你想把你的秘密保存在一个 txt 文件中,那么你必须手动读取和解析 txt 文件。
标签: java spring-boot yaml microservices spring-webflux