Search code examples
springspring-bootclasspathtruststore

Unable to reach truststore file with in spring boot jar: trustAnchors parameter must be non-empty


I have set my application with trustore and works fine with my local deployment. However when I deploy through the generated jar, it fails. That is because I have it like,

System.setProperty("javax.net.ssl.trustStore", "src/main/resources/cacert");

But my jar has the structure, /BOOT-INF/classes/cacert. Though I changed my system property to,

System.setProperty("javax.net.ssl.trustStore", "BOOT-INF/classes/cacert");

It did not meet the requirement, due to this reason I get

trustAnchors parameter must be non-empty error.

Solution

  • Just by setting the system property with truststore file location or mentioning src/main/resources would not help. Rather the create a temporary file in the application and copy the contents of truststore file to it. Then set that file in your system property by getting its get path. This way there is no need to hard code path or use an alternative classpath.

    Details can be found here. Thanks to avasseur-pivotal.