Java Jasypt无法使用Spring从系统环境变量解密密码
我有jasypt密码和application.yml中定义的加密密码,如下所示:Java Jasypt无法使用Spring从系统环境变量解密密码,java,spring,spring-boot,jasypt,Java,Spring,Spring Boot,Jasypt,我有jasypt密码和application.yml中定义的加密密码,如下所示: jasypt: encryptor: password: ${secretKey} spring: datasource: password: ENC(${password}) 并对其使用@Value: @Value("${spring.datasource.password}") private String springPassword; 我已经在环境变量中定义了secr
jasypt:
encryptor:
password: ${secretKey}
spring:
datasource:
password: ENC(${password})
并对其使用@Value:
@Value("${spring.datasource.password}")
private String springPassword;
我已经在环境变量中定义了secretKey和password。但当我启动这个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'
如果我对这两个键都硬编码,它就可以正常工作了
任何帮助都将不胜感激。我也有类似的问题。在我的例子中,原因是我在类路径上有jasypt-1.9.2.jar和jasypt-1.9.4.jar jasypt-1.9.4.jar作为依赖项来自jasypt spring boot 2.1.1。 jasypt-1.9.2.jar作为依赖项来自wss4j ws-security common 2.2.2
改用jasypt spring boot 2.1.0解决了我的问题。我知道为时已晚,但仍然如此。对我来说,将ENC()方法作为环境变量的一部分传递是有效的
jasypt:
encryptor:
password: ${secretKey}
spring:
datasource:
password: ${PASSWORD}
在设置环境变量时
export PASSWORD=ENC(yourPassword)
我使用maven作为依赖项处理程序,没有依赖项重叠。maven无法解决依赖项冲突,因为jasypt 1.9.2有groupId='org.jasypt',而jasypt 1.9.4有groupId='com.melloware'。但是内部的类在相同的包(org.jasypt…)中,并且具有相同的名称。