【发布时间】:2020-12-03 13:30:20
【问题描述】:
我有一个 Spring Boot 应用程序和一个属性文件 config.properties,其中的值是加密的(请参见下面的示例)
config.properties
myapp.property1={5AES123}SafeR70/wqqwwqwqwqwqsdaWQmNs+O2afeIU/1MHoCWvTgxUYA30C/rrei4\=
myapp.property2={5AES342}MareV70/PLNqsasasaa*ksueoHH+O2afeIU/1MHoCWvTgxUYJQ30C/7rei4\=
myapp.property3={5AES111}TutoV10/xdtghshI5CVULQ7uevr+O2afeIU/1MHoCWvTgxUYJQ30C/1rei4\=
我正在使用特殊的 API(作为 POM 依赖项添加到我的应用中)来解密这些值。
请在下面找到伪代码,以更好地解释我的意图以及我希望在一天结束时拥有的东西。
public static void main(String[] args) {
// 1. decrypt the properties values of the config.properties using my special API package.
List<MyPropDecrypted> myPropDecryptedLst = mySpecialAPIPack.decrpyt("config.properties");
// 2. get the spring context
myAppSpringContext = getSpringContext();
//3. add the decrypted properties to the spring context from step 2.
int idx = 0;
for (MyPropDecrypted myPropDecrypted : myPropDecryptedLst){
idx++;
myAppSpringContext.setProperty("myapp.property"+idx, myPropDecrypted.getDecrypteValue();
}
SpringApplication.run(Application.class, args);
}
我的问题是如何以编程方式将那些解密的(使用我的特殊 API)属性添加/注入到 spring 上下文中,以便我可以像从属性文件加载的属性一样使用它(@Value("${myapp.property1 }"))?
【问题讨论】:
标签: java spring spring-boot properties