java - Jasypt 无法使用 Spring 从系统环境变量中解密密码
问题描述
我有 jasypt 密码和 application.yml 中定义的加密密码,如下所示:
jasypt:
encryptor:
password: ${secretKey}
spring:
datasource:
password: ENC(${password})
并为此使用@Value:
@Value("${spring.datasource.password}")
private String springPassword;
我已经在我的环境变量中定义了 secretKey 和密码。但是当我启动这个 spring boot 应用程序时,它会抛出错误:
Caused by: org.springframework.cache.Cache$ValueRetrievalException: Value for key 'spring.datasource.password' could not be loaded using 'com.ulisesbocchio.jasyptspringboot.caching.CachingDelegateEncryptablePropertySource$$Lambda$209/172678484@5ae15'
如果我对两个键都进行硬编码,那么它就可以正常工作。
任何帮助,将不胜感激。
解决方案
我知道为时已晚,但仍然如此。对我来说,将 ENC() 方法作为环境变量的一部分传递是有效的。
jasypt:
encryptor:
password: ${secretKey}
spring:
datasource:
password: ${PASSWORD}
在设置环境变量时
export PASSWORD=ENC(yourPassword)
推荐阅读
- javascript - React Tensorflow JS 加载用户上传的csv文件
- r - 在 ggplot2 中使用 facet_wrap() 对齐标题对齐?
- asp.net - ASP.NET 如何从某些列为空的表中获取前 10 名
- kubernetes - 如何根据 EKS 中的平均内存使用量自动扩展 Kubernetes Pod?
- multithreading - 使用 bufio.NewWriter 但不使用 io.MultiWriter 的竞争条件
- python - 如何在函数内调用任意数量的函数?
- javascript - 如何在 Mongoose 中正确创建数组模式并按给定条件过滤?
- maven - 为什么 Maven 在第一次执行时需要很多时间
- python - 动态更新其他字典函数中的字典值
- bash - 如何在bash中捕获特定关键字前面的数字