I am trying to read some credentials from env variables in custom.properties file but it's not able to recognize code for my properties file given below but it's not working the way I am fetching env variable like this "${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"
can someone please help me out how to get env variables to custom.properties file and
Kindly try with the below sample code .
it reads properties from custom properties file and with prefix value . for eg :Below example reads value from properties with the key of 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;
}
Use 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();
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.