Search code examples
springspring-bootssllets-encryptcertbot

Spring Boot 2.7.1 LetsEncrypt PEM keystore throws Resource location must not be null


So I read that Spring Boot now supports PEM since 2.7.0

https://docs.spring.io/spring-boot/docs/2.7.0-SNAPSHOT/reference/htmlsingle/#howto.webserver.configure-ssl 17.3.7. Configure SSL

So I am using PEM generated by certbot.

My application.properties

spring.jpa.generate-ddl=true
spring1.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false
server.port=443
server.ssl.certificate=fullchain1.pem
server.ssl.certificate.certificate-private-key=privkey1.pem
server.ssl.trust-certificate=fullchain1.pem

When I launch I get

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Could not load key store 'null'

Caused by: org.springframework.boot.web.server.WebServerException: Could not load key store 'null'

Caused by: java.lang.IllegalArgumentException: Resource location must not be null


Solution

  • As per the documentation SSL configuration springboot

    UPDATE:

    Adding the content from link to directly in the answer, as link can get updates

    SSL can be configured declaratively by setting the various server.ssl.* properties, typically in application.properties or application.yml. The following example shows setting SSL properties using a Java KeyStore file:

    server.port=8443
    server.ssl.key-store=classpath:keystore.jks
    server.ssl.key-store-password=secret
    server.ssl.key-password=another-secret
    

    The following example shows setting SSL properties using PEM-encoded certificate and private key files:

    server.port=8443
    server.ssl.certificate=classpath:my-cert.crt
    server.ssl.certificate-private-key=classpath:my-cert.key
    server.ssl.trust-certificate=classpath:ca-cert.crt
    

    Your properties are not correctly declared,

    server.ssl.certificate.certificate-private-key=privkey1.pem should be changed to server.ssl.certificate-private-key=privkey1.pem