keytool -genkey -alias tomcat -keyalg RSA -keystore server.keystore
application.yml
server: port: 8324 http: port: 8325 ssl: key-store: ./src/main/resources/server.keystore key-alias: tomcat enabled: true key-store-password: P@ssw0rd key-store-type: JKS
server.http.port
指http的端口server.port
指的是https的端口key-store
指證書路徑key-store-password
指第一步中輸入的祕鑰庫口令https://127.0.0.1:8324/xxx
驗證,以下:TomcatConfig
配置文件,讀取配置文件中http
的端口配置http
訪問import org.apache.catalina.connector.Connector; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class TomcatConfig { @Value("${server.http.port}") private int httpPort; @Bean public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { TomcatEmbeddedServletContainerFactory containerFactory = (TomcatEmbeddedServletContainerFactory) container; Connector connector = new Connector(TomcatEmbeddedServletContainerFactory.DEFAULT_PROTOCOL); connector.setPort(httpPort); containerFactory.addAdditionalTomcatConnectors(connector); } } }; } }
http
bulid/webpack.dev.conf.js
文件下配置derServer.https
爲true
https://localhost:端口
,以下: