一.创立springBoot我的项目
二.配置ssl证书
- 将证书放到我的项目的resources文件夹下,如下图所示
- 在application.yml 文件中做如下配置(如果你的我的项目是application.properties能够批改后缀名为yml或者能够参考yml写法做响应的批改)
server: port: 6443 ssl: key-store: classpath:springboot.p12 key-store-password: 123456 keyStoreType: PKCS12 enabled: truehttp: port: 6880
三.创立Tomcat配置类
package com.example.demo.config;import org.apache.catalina.connector.Connector;import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;import org.springframework.boot.web.servlet.server.ServletWebServerFactory;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;/** * @author TM-majian * @version 1.0 * @since 2021/5/7 19:21 */@Configurationpublic class SSLConfig { @Value("${http.port}") private Integer port; @Bean public ServletWebServerFactory servletContainer() { TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setPort(port); tomcat.addAdditionalTomcatConnectors(connector); return tomcat; }}
四.创立controller测试
import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/** * @author TM-majian * @version 1.0 * @since 2021/5/7 19:19 */@RestControllerpublic class TestController { @RequestMapping("/helloHttps") public String helloHttps(){ return "hello https"; }}
五.启动我的项目测试
- 本地测试
通过控制台日志能够看到两个端口都已启动实现,浏览器拜访http连贯http://localhost:6880/helloHttps
拜访https连贯
https://localhost:6443/helloH...