1. 需要一个证书,可以自己生成或者购买。下面是我们通过keytool自己生成。
生成命令: keytool -genkey -alias tomcat -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650
2.配置application.yml
server: port: 8443 ssl: key-store: classpath:keystore/keystore.p12 key-store-password: 5xing88 key-store-type: PKCS12 key-alias: tomcat
3.同时支持http https
@Beanpublic EmbeddedServletContainerFactory servletContainer() { TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(); tomcat.addAdditionalTomcatConnectors(createSslConnector()); return tomcat;}private Connector createSslConnector() { Connector connector = new Connector(); //配置 return connector;}