我正试图从custom.properties文件中的env变量中读取一些凭据,但它无法识别下面给出的属性文件的代码,但它的工作方式与我获取env变量的方式不同,如"${varName}"
org.apache.ws.security.crypto.provider=org.apache.wss4j.common.crypto.Merlin
# Type - Valid Keystore Type. Eg - pkcs12 , jks
org.apache.ws.security.crypto.merlin.keystore.type=jks
# Keystore Password
org.apache.ws.security.crypto.merlin.keystore.password=${keystorePassword}
# Keystore Private Password
org.apache.ws.security.crypto.merlin.keystore.private.password=${keystorePassword}
# Keystore Alias
org.apache.ws.security.crypto.merlin.keystore.alias=${keystoreAlias}
# Keystore File Name
org.apache.ws.security.crypto.merlin.keystore.file="something.jks"
有人能帮我如何将env变量添加到custom.properties文件和中吗
请尝试使用以下示例代码。
它从自定义属性文件中读取具有前缀值的属性。例如:下面的示例使用org.apache.ws.security.crypto.provider 的密钥从属性中读取值
@Configuration
@PropertySource(value = "classpath:<properytfilename>.properties")
@ConfigurationProperties(prefix = "org.apache.ws.security.crypto")
public class CustomProperties {
private String provider;
}
使用java.util.Properties
....
@Value("${what.ever.env}")
private String keystorePassword;
...
Properties properties = new Properties();
properties.setProperty("org.apache.ws.security.crypto.provider", "org.apache.wss4j.common.crypto.Merlin");
properties.setProperty("org.apache.ws.security.crypto.merlin.keystore.password", keystorePassword);
File file = new File("custom.properties");
FileOutputStream fileOut = new FileOutputStream(file);
properties.store(fileOut, "Comment here");
fileOut.close();
...