ssl-guides 2026-12-04 ⏱ 4 min read

Enable HTTPS in Spring Boot with Free SSL

Enable HTTPS in Spring Boot with Free SSL

HTTPS in Spring Boot takes one keystore or a pair of PEM files, plus a handful of properties. Here are both setups, the redirect from port 8080, and the renewal trap that takes a site down.

Decide the architecture first

SetupCertificate lives inFits
Spring Boot terminates TLSThe app's keystore or PEM filesSingle service, no proxy, container published on 443
Proxy terminates TLSNginx, a load balancer or an ingressSeveral services, Kubernetes, or a shared host

If a proxy or ingress terminates TLS, do not configure SSL in the application at all. Configure forwarded headers instead, or every redirect and generated URL will point at http or at the wrong port.

HTTPS in Spring Boot, option 1: a PKCS12 keystore

Build the keystore from your certificate, chain and key:

openssl pkcs12 -export \
  -in fullchain.pem -inkey privkey.pem \
  -out keystore.p12 -name springboot \
  -passout pass:ChangeMe123

Put it in src/main/resources/ and add the properties:

server.port=8443
server.ssl.key-store=classpath:keystore.p12
server.ssl.key-store-password=ChangeMe123
server.ssl.key-store-type=PKCS12
server.ssl.key-alias=springboot

The alias has to match the -name you used. When it does not, startup fails with a message about the key alias not being found, which is easy to misread as a password problem.

HTTPS in Spring Boot, option 2: PEM files directly

Recent Spring Boot versions read PEM without a keystore, which removes the conversion step entirely and makes rotation a file swap.

server.port=8443
server.ssl.certificate=classpath:fullchain.pem
server.ssl.certificate-private-key=classpath:privkey.pem

Whether your version supports these keys is worth confirming against the documentation for the release you are on. On older versions the keystore route is the supported one, and mixing the two styles produces a confusing startup error rather than a clear warning.

Run both HTTP and HTTPS during the change

A second connector lets you keep http alive while you verify https, then redirect once you are sure.

@Bean
public TomcatServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory f =
        new TomcatServletWebServerFactory();
    f.addAdditionalTomcatConnectors(redirectConnector());
    return f;
}

private Connector redirectConnector() {
    Connector c = new Connector(
        "org.apache.coyote.http11.Http11NioProtocol");
    c.setScheme("http");
    c.setPort(8080);
    c.setSecure(false);
    c.setRedirectPort(8443);
    return c;
}

Remove it once the redirect is handled somewhere more permanent, such as the proxy or the platform in front of the app.

Behind a proxy: forwarded headers

If TLS ends at a proxy, the app sees plain HTTP and builds http:// links, which breaks OAuth callbacks, redirects and cookie flags. Fix it with one property:

server.forward-headers-strategy=framework

Then make sure the proxy actually sends X-Forwarded-Proto and X-Forwarded-For. Without those headers the setting has nothing to read, and the symptom looks like a Spring problem when it is a proxy configuration.

Test it properly

curl -vI https://localhost:8443/ 2>&1 \
  | grep -E 'SSL|subject|issuer|HTTP/'

openssl s_client -connect localhost:8443 \
  -servername example.com </dev/null 2>&1 \
  | grep 'Verify return code'

A return code of 0 means the chain validates. Anything else points at a missing intermediate, which is the most common failure when a keystore was built from a leaf certificate alone.

Then check the public hostname with the SSL checker, which sees what a browser sees rather than what localhost serves. If the service should not offer old protocol versions, confirm with the TLS checker.

Getting the certificate

Any publicly trusted certificate works, and it does not have to cost anything: free certificates are issued in the browser, cover the base domain plus www, and give you the PEM files both options above need. If you want the keystore without a terminal, the SSL converter builds a PKCS12 from the PEM pair, and the key matcher confirms the pair before you ship it.

Renewal in a container

A certificate baked into an image expires with the image. Mount it as a secret or a volume instead, so renewal is a file replacement and a restart rather than a rebuild. Put the expiry date in a calendar with an alert 14 days out, and start the renewal when a third of the lifetime is left (Let's Encrypt announcement): nothing in Spring Boot will warn you.

Related reading: converting PEM to a Java keystore, installing a certificate on Tomcat, securing an API gateway with TLS and SSL for Node.js.

Frequently Asked Questions

Does Spring Boot renew the certificate?

No. It loads whatever file you point it at and keeps it in memory until it restarts. Renewal is a job on the host, plus a reload, and nothing in the framework reminds you.

Keystore or PEM, which should I choose?

PEM if your renewal tool already writes PEM files, because no conversion step can go stale. A keystore if you already have one from a Java toolchain.

How do I redirect HTTP to HTTPS?

Add a second Connector on port 8080 and a security rule that sends every request to the HTTPS port, or terminate TLS at a proxy and let Spring Boot trust its headers.

🔒 Test Your Website SSL Certificate Now
Run Free SSL Check →

✅ Post-Installation Verification & SEO Checklist

After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:

  • Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
  • Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
  • Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
  • Confirm both root and www versions resolve cleanly to one canonical HTTPS URL.
  • Verify your HTTPS property and sitemap.xml inside Google Search Console and Bing Webmaster Tools.
Technically Reviewed by TryFreeSSL Security Team
Last updated: 2026-12-05
About Us →

Free SSL Certificates, Live SSL Checker & CSR Generator

Issue trusted Let's Encrypt SSL certificates in 60 seconds with zero server setup.

Related Articles

🤖 TryFreeSSL AI Assistant