简体   繁体   中英

Configuring SSL on Tomcat/Spring Boot ("Could not find key store classpath:keystore.jks" error)

I'm trying to configure SSL. Hovever, I get an exception saying

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Could not find key store classpath:keystore.jks

This is my application-https.properties file:

server.port = 8443
server.ssl.key-store = classpath:keystore.jks
server.ssl.key-store-password = secret
server.ssl.key-password = another-secret
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/postgres?currentSchema=myschema
spring.datasource.username=postgresql
spring.datasource.password=postgresql
spring.datasource.driverClassName=org.postgresql.Driver

My application.properties:

spring.profiles.active=https

I've read documentation about ssl and I don't know what's wrong. Any help will be appreciated.

Make sure you did the following:

  1. placed the .jks file inside main/resources.
  2. you ran the command: mvn clean install

Keystore is not readable from classpath other than Spring. (In case of kafka we don't have any option and kafka always expect location to be on filesystem not in jar file.) So I suggest to use below property and give absolute path to keystore location.

application.properties

spring.kafka.ssl.key-store-location=file:certificate.jks

In code:

@Value("${spring.kafka.ssl.key-store-location}")
    private Resource keystoreLocation;

props.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, keystoreLocation.getFile().getAbsolutePath());

This way you can read the keystore. You may need to copy the file on file system rather than in Jar.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM