1.生成证书

keytool -genkey -alias tomcat -keyalg RSA -keystore E:/https.keystore

  spring boot 开启https-LMLPHP

将生成好的证书放在项目根目录即可

2 修改配置文件

server:
port: 443
servlet:
context-path: /
tomcat:
uri-encoding: UTF-8
max-threads: 1000
min-spare-threads: 30
ssl:
#生成证书的名字
key-store: https.keystore
#密钥库密码
key-store-password: 123456
key-store-type: JKS
key-alias: tomcat

 3 开启访问80端口跳转433端口

package com.yjkj.repository;

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.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean; @SpringBootApplication
public class RepositoryApplication extends SpringBootServletInitializer { public static void main(String[] args) {
SpringApplication.run(RepositoryApplication.class, args);
} @Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addAdditionalTomcatConnectors(createHTTPConnector());
return tomcat;
} private Connector createHTTPConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
//同时启用http(80)、https(8443)两个端口
connector.setScheme("http");
connector.setSecure(false);
connector.setPort(80);
connector.setRedirectPort(443);
return connector;
}
}

https访问

  spring boot 开启https-LMLPHP

http访问

spring boot 开启https-LMLPHP

05-20 22:08