Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Jasypt无法使用Spring从系统环境变量解密密码_Java_Spring_Spring Boot_Jasypt - Fatal编程技术网

Java Jasypt无法使用Spring从系统环境变量解密密码

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密码和application.yml中定义的加密密码,如下所示:

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…)中,并且具有相同的名称。