Small question regarding Java SpringBoot application.properties please.
I have a simple SpringBoot web application, and during the business flow, it needs the javax.net.ssl. trustStore trustStorePassword keyStore keyStorePassword to be set.
Therefore, in the main, this is what I tried:
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
System.setProperty("javax.net.ssl.trustStore", "truststore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.keyStore", "keystore.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
SpringApplication.run(MyApplication.class, args);
}
}
And I verified, this works fine. (removing the property from here will cause my app to fail) Therefore, I would believe those properties works.
I understand I can pass those as command line, but I would like to use application.properties, where all my other properties are.
Now, I would like to externalize those properties into the application.properties / yml please.
What I tried:
server.port=8080
javax.net.ssl.trustStore=truststore.jks
javax.net.ssl.trustStorePassword=changeit
javax.net.ssl.keyStore=keystore.jks
javax.net.ssl.keyStorePassword=changeit
However, those properties are not taken account, I am getting the same behaviour as if I did not set anything.
May I ask, how to set those system properties in application.properties please?
Thank you
application.properties. What do you need this for? If they are for tomcat (for https) you can configure some tomcat specific properties.application.propertiesyou still would need something that exposes them as system properties. That is build in by default so you would have to build your own solution for that. Problem is if you want to load the properties you either have to make sure they execute early (maybe anEnvironmentPostProcessor) or some custom code that runs before that and loads the file itself (but that beats the purpose) or you find a different way to setup the 3rd party dependency (with explicitly setting the key-/truststore on it instead of relying on system properties).