1.使用JDK自带工具keytool生成ssl证书(tomcat.keystore)自行搜索 网上一大堆教程
2.修改项目配置文件
# http 端口
server.http.port=8090
# https 端口
server.port=9090
#文件地址
server.ssl.key-store=D:\tomcat.keystore
#生成tomcat.keystore 时候的别名
server.ssl.key-alias=tomcat
server.ssl.enabled=true
#密码
server.ssl.key-store-password=123456
server.ssl.key-store-type=JKS
3.配置类
@Configuration
@PropertySource(value="classpath:application.properties")
public class HttpComponent {
//读取application.properties配置文件配置的http监控端口
@Value("${server.http.port}")
public int SYSTEM_HTTP_PORT;
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addAdditionalTomcatConnectors(createStandardConnector()); // 添加http
return tomcat;
}
private Connector createStandardConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(SYSTEM_HTTP_PORT);
connector.setSecure(false);
connector.setRedirectPort(443);
return connector;
}
}