Application
Spring web application on port 8443
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Main
Map entries to Rest Controller.
/**
* Rest Controller service
*/
package com.minte9.https;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@GetMapping("/")
public String welcome() {
return "Welcome";
}
@GetMapping("/hello")
public String hello() {
return "Hello World";
}
}
Port
Set port as 8443 in application.properties
// src/resources/application.properties
server.port:8443
http://127.0.0.1:8443/hello
// Hello World
Certificate
Create self-signed certificate, using java keytool in a new certs/ in root directory.
cd src/resources/certs/
keytool -genkey -alias tomcat -storetype PKCS12 \
-keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650
Configure
Update application.properties configuration values.
server.port = 8443
server.ssl.key-store = classpath:certs/keystore.p12
server.ssl.key-store-password = mypassword
server.ssl.keyStoreType = PKCS12
server.ssl.keyAlias = tomcat
Run
Check that https is enabled on localhost.
mvn spring-boot:run
https://127.0.0.1:8443/hello
// Hello World
PKCS12
If you already have .crt and .key files generated, you need to convert them.
openssl pkcs12 -export -in certs/myserver.crt -inkey certs/myserver.key \
-out certs/myserver.p12 -name myserver
Last update: 467 days ago