I am using springBootVersion 1.2.0.RELEASE.
I'm trying to have my keystore and truststore configured through application.properties
.
When I add the following settings, I can get the keystore to work, but not the truststore.
server.ssl.key-store=classpath:foo.jks
server.ssl.key-store-password=password
server.ssl.key-password=password
server.ssl.trust-store=classpath:foo.jks
server.ssl.trust-store-password=password
However, if I add the truststore through gradle:
bootRun {
jvmArgs = [ "-Djavax.net.ssl.trustStore=c://foo.jks", "-Djavax.net.ssl.trustStorePassword=password"]
}
it works just fine.
Has anyone used the application.properties
for trust stores?
In case if you need to make a REST call you can use the next way.
This will work for outgoing calls through
RestTemplate
.Declare
RestTemplate
bean like this.Where
http.client.ssl.trust-store
andhttp.client.ssl.trust-store-password
points to truststore inJKS
format and the password for the specified truststore.This will override the
RestTemplate
bean provided with Spring Boot and make it use the trust store you need.I had the same problem with Spring Boot, Spring Cloud (microservices) and a self-signed SSL certificate. Keystore worked out of the box from application properties, and Truststore didn't.
I ended up keeping both keystore and trustore configuration in application.properties, and adding a separate configuration bean for configuring truststore properties with the System.
I know this is pretty old but if anyone encounters this what I did was add another property to my properties file.
So first you create the trust store and set the properties in the properties file. Then, according to this, you add
server.ssl.client-auth=need
in order to force Spring only to accept requests carrying a certificate accepted by those in your trust store.This method solved my issue.