Enable HTTPS in Spring Boot Application

Video guide of the process



Step 1 : Generate SSL Certificate

To enable HTTPS, we would require a SSL certificate. This certificate can be obtained from a Certificate Authority.
Also, we can generate a self-signed certificate using java keytool utility.

1
2
3
4
keytool -genkey -noprompt -alias chocolate \
-storetype PKCS12 -keyalg RSA -keysize 2048 -validity 365 \
-keystore chocolate.p12 -keypass chocolate -storepass chocolate \
-dname "CN=snmaddula, OU=security, O=snmaddula, L=waverock, S=Hyderabad, C=IN"

This will generate a PKCS12 keystore file as chocolate.p12 with the newly generated certificate.

Step 2 : Configure SSL connector for Server

To enable HTTPS in our application, we need to configure few ssl properties binding the application server with the keystore that was generated in the previous step.

Add the below configuration to your application.yml

1
2
3
4
5
6
7
8
server:
port: 8443

ssl:
key-store: classpath:chocolate.p12
key-alias: chocolate
key-store-password: chocolate
key-store-type: PKCS12

That’s all you need to enable HTTPS in a spring boot application.

You can now access the application with the endpoint: https://localhost:8443

You would need to add the Security Certificate Exception in this was a self-signed certificate.