Skip to content

In this example, I will explain how to enable HTTPS(SSL) in Spring Boot. The self-signed certificate is used in this example, and configure a simple REST Spring Boot application.

License

Notifications You must be signed in to change notification settings

rowishva/Enable-https-SSL-for-Spring-Boot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Enable https(SSL) for Spring Boot

In this example, I will explain how to enable HTTPS(SSL) in Spring Boot. The self-signed certificate is used in this example, and configure a simple REST Spring Boot application.

Technology Stack
+ Java 11
+ Spring Boot 2.5.8
+ Spring Boot Rest API
+ SSL

Generate Self-signed Certificate

The first step is to generate will use the JDK’s keytool to generate a self-sign certificate in PKCS12 format using JDK Keytool. Below command will create a PKCS12 cert after that put this file into the resources folder under SpringBoot project

keytool -genkeypair -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore springboothttps.p12 -validity 365

image

Configure Properties

server.port=8443
server.ssl.key-store=classpath:springboothttps.p12
server.ssl.key-store-password=password
server.ssl.keyStoreType=PKCS12

Rest Controller

Create simple Rest endpoint which return "Hello HTTPS"

package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
	
    @GetMapping("/hello")
    public String sayHello() { 
        return "Hello HTTPS";
    }

}

Start the server, It is ready to be tested now.

Test in browser

image

Test in Postman

Postman provides a way to set SSL certificates on a per-domain basis. To manage your client certificates, go to Settings, and select the Certificates tab. Add your certificate as below

image

Author

About

In this example, I will explain how to enable HTTPS(SSL) in Spring Boot. The self-signed certificate is used in this example, and configure a simple REST Spring Boot application.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages