Quick revision
The short answer
Spring Boot 3.1 introduced SSL bundles: we define a named bundle once, under spring.ssl.bundle.jks.<name> for keystores such as PKCS12 or spring.ssl.bundle.pem.<name> for PEM files, and reuse it by name. The embedded server uses it with server.ssl.bundle=<name>, and outgoing calls apply a client bundle to RestClient or WebClient through the SslBundles bean or the builders' SSL support. For mutual TLS the client bundle holds its own key and certificate plus a truststore with the server's CA, and recent Boot versions can reload bundles when the files change (reload-on-rebuild); check your version.
What to remember
In this answer, we configured TLS with SSL bundles, available since Spring Boot 3.1. We defined a named PKCS12 bundle under spring.ssl.bundle.jks and a PEM client bundle, served HTTPS with server.ssl.bundle, and applied the client bundle to RestClient and WebClient through SslBundles and the builders' SSL support. For mutual TLS, the client bundle carries its own key and certificate plus a truststore with the server's CA, and reload-on-rebuild lets supporting components pick up renewed certificates without a restart.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Spring Boot 3.1 introduced SSL bundles: we define a named bundle once, under spring.ssl.bundle.jks.<name> for keystores such as PKCS12 or spring.ssl.bundle.pem.<name> for PEM files, and reuse it by name. The embedded server uses it with server.ssl.bundle=<name>, and outgoing calls apply a client bundle to RestClient or WebClient through the SslBundles bean or the builders' SSL support. For mutual TLS the client bundle holds its own key and certificate plus a truststore with the server's CA, and recent Boot versions can reload bundles when the files change (reload-on-rebuild); check your version.
Why this question is asked
TLS configuration used to be one of the messiest parts of a Spring Boot service. The server had its own server.ssl properties, and every HTTP client needed hand-written code to load a KeyStore, build an SSLContext and plug it into Apache HttpClient or Netty, each slightly differently. SSL bundles fixed that by giving TLS material a name. Interviewers ask this coding question to check whether we know the modern approach and understand what mutual TLS actually needs on each side. In this answer, we will recap keystores, truststores and mTLS, configure the server with a PKCS12 bundle, call another service with mTLS from RestClient and WebClient, and look at certificate reloading.
1A Quick Recap of Keystores, Truststores and mTLS
A keystore holds our own private key and certificate chain, which prove who we are. A truststore holds the certificates of the certificate authorities (CAs) we trust, which we use to check who the other side is. PKCS12 is the standard keystore file format (.p12), and since Java 9 it is the default keystore type. PEM is the text format with -----BEGIN CERTIFICATE----- blocks that many tools such as cert-manager produce.
In ordinary TLS only the server proves its identity. In mutual TLS (mTLS) the client also presents a certificate, and the server checks it against its truststore. So for mTLS each side needs both: a keystore with its own identity and a truststore that trusts the other side's CA.
| Side | Keystore (who I am) | Truststore (whom I trust) |
|---|---|---|
| Server, plain TLS | server key and certificate | not needed |
| Server, mTLS | server key and certificate | CA that signed client certificates |
| Client, plain TLS | not needed | CA that signed the server certificate |
| Client, mTLS | client key and certificate | CA that signed the server certificate |
2Defining the Bundles
Bundles live under spring.ssl.bundle. The jks group is for Java keystores, including PKCS12 despite the name, and the pem group is for PEM files. Each bundle has a keystore part, a truststore part, or both. We define one bundle for the server and one for outgoing calls to the payments service.
Notice that the keystore password comes from an environment variable or secret store, not from the file. For the client we chose PEM because cert-manager on Kubernetes writes tls.crt and tls.key files; a PKCS12 file would work just as well under the jks group.
3Serving HTTPS With the Bundle
The embedded server, whether Tomcat, Jetty or Netty, takes the bundle by name. We no longer set server.ssl.key-store and friends individually.
4Calling Another Service With mTLS
For outgoing calls, Spring Boot gives us an SslBundles bean that looks bundles up by name. RestClient.Builder and WebClient.Builder can use a bundle through Boot's client HTTP request factory support. The simplest route is the auto-configured RestClientSsl and WebClientSsl helpers, which apply a bundle to the builder by name; at a lower level we can pass a bundle from SslBundles to the request factory settings. The exact helper names have moved a little between 3.1 and 4.0 (for example ClientHttpRequestFactorySettings became HttpClientSettings in newer versions), so check your version.
So the client presents the certificate from tls.crt with the key from tls.key, and checks the payments server's certificate against payments-ca.crt. Notice what is not in this code: no KeyStore.getInstance, no KeyManagerFactory, no SSLContext. The bundle turns the configuration into a ready SSLContext, and the same bundle can be reused by other clients, Kafka or database connections that support bundles.
5Reloading Certificates When They Change
Certificates from cert-manager or a service mesh often live for 90 days or less, and renewing them should not need a restart. With reload-on-rebuild: true, Spring Boot watches the bundle's files and, when they change, rebuilds the bundle and notifies the components that registered for updates. The embedded web server supports this, so new TLS handshakes use the new certificate while existing connections continue.
But there is a catch: not every consumer of a bundle reacts to updates. A RestClient built once at startup may keep its original SSLContext. Check your version's documentation for which components support reloading, and for others plan a rolling restart before the old certificate expires. Monitoring certificate expiry dates is cheap insurance either way.
6Follow-up questions
Why is the group called jks if we use PKCS12?
The jks group covers any Java KeyStore type, and the type property selects the format. PKCS12 is the default type in modern Java, so a .p12 file is configured under jks with type PKCS12 or simply left to the default.
Should we disable hostname verification for internal services?
No. Hostname verification checks that the certificate belongs to the host we meant to call; without it, any certificate from the trusted CA is accepted, which defeats much of the point. Issue internal certificates with the right DNS names in the subject alternative names instead.
7Conclusion
In this answer, we configured TLS with SSL bundles, available since Spring Boot 3.1. We defined a named PKCS12 bundle under spring.ssl.bundle.jks and a PEM client bundle, served HTTPS with server.ssl.bundle, and applied the client bundle to RestClient and WebClient through SslBundles and the builders' SSL support. For mutual TLS, the client bundle carries its own key and certificate plus a truststore with the server's CA, and reload-on-rebuild lets supporting components pick up renewed certificates without a restart.
Open with
Since Spring Boot 3.1 I would use SSL bundles. A bundle is named TLS material defined once in configuration. For the server I define spring.ssl.bundle.jks.web-server with the PKCS12 keystore location, type PKCS12, the key alias and the password from a secret, and then set server.ssl.bundle to web-server.
Then, if they want more
The embedded server serves HTTPS with it, and I no longer need the individual key-store properties. For the outgoing call with mutual TLS, I define a second bundle, say payments-client, either PEM files from cert-manager or another PKCS12 file.
It needs two parts: a keystore with the client's own key and certificate, which the payments service checks, and a truststore with the CA that signed the payments server's certificate, so my client can verify the server.
Then I inject SslBundles and apply the bundle to the client: for RestClient through the RestClientSsl helper and for WebClient through WebClientSsl, both with fromBundle, or at a lower level through the request factory settings. That replaces all the old code that built KeyManagerFactory and SSLContext by hand, and the same bundle can be reused by other clients.
If the server should require client certificates, I set server.ssl.client-auth to need and give the server bundle a truststore. Finally, setting reload-on-rebuild lets Boot pick up renewed certificate files without a restart for components that support it; the exact helper names and reload support vary by version, so I would check the docs for the version in use.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 3.1, Java 9
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Security reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Configure a Spring Boot 3.1 or later service to serve HTTPS using a PKCS12 keystore and...": https://scrivio-interview-library.netlify.app/spring-boot/secrets-and-crypto/b68f600d40/