The Jar deployment server of SpringBoot 2.x uses HTTPS to configure SSL

Step 1: alicloud configures the security rules of the security group and configures the access ports
To use alicloud 4438080 and other ports, you need to configure a security group before you can access it through this port

If you do not configure ports, you can refer to the previously written Alibaba cloud to obtain free SSL certificates. A detailed picture and text explanation for opening Alibaba cloud ports is attached. At the end of the text, there is a detailed picture and text tutorial for opening ports

Step 2: purchase alicloud's free certificate
You can enter the SSL certificate and click purchase certificate

Click the purchase certificate, enter the page shown in the figure below, and select the free version (personal) DV

If you can't find the certificate list, you can also directly search https, select ssl certificate and click buy to purchase

Step 3: download the SSL certificate of the corresponding server

Step 4: before spring boot 2.X packs Jar, modify the configuration:

import org.apache.catalina.connector.Connector;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
public class TestApplication {
    public static void main(String[] args) {, args);
    //The following is the configuration of 2.0. 1.x, please search the corresponding settings
    public ServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
        return tomcat;
    private Connector createHTTPConnector() {
        Connector connector = new             Connector("org.apache.coyote.http11.Http11NioProtocol");
        //Enable both http (8080) and https (8443) ports at the same time
        return connector;
Two ways to write configuration files
application.yml Configuration in:
 port: 8443 #Access port number
    key-store: route/Name of the certificate.pfx
    key-store-password: Certificate password Medium configuration
server.servlet.context-path=Project address
server.ssl.key-store=route/Name of the certificate.pfx
server.ssl.key-store-password=Certificate password 

Step 5: run jar
Upload the jar to the server, enter the current directory of jar through cmd command, and enter java -jar xxx.jar to run

You can also directly click shift + right mouse button in the current jar folder to open cmd and directly run java -jar xxx.jar to run the project

Appendix I: domain name resolution
Find the domain name in the Alibaba cloud menu, click the domain name list to see the purchased domain name, and click resolve

Click Add record

Select record type, host record and record value. The record value here is the public ip of the server (record type A points to IPV4). Click OK to resolve it

There is another common resolution method. The record type is CNAME. Pointing this domain name to another domain name is generally to resolve the value of this domain name to cdn

Appendix II jar package of spring boot
Select your project, right-click and select Run as - maven clean to clear the previous compiled files, and then select Run as - maven install to generate jar files in the targer directory of the project, provided that the packaging method of pom configuration is jar~

Tags: Java Spring Boot SSL https

Posted on Mon, 25 Oct 2021 23:23:49 -0400 by PaTTeR