1、生成jdk生成ssl证书
MAC系统:keytool -genkey -alias your.alias(别名随便起) -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 validity 3650
Windows系统,请在JDK目录下找到keytool.exe
keytool -genkey -alias your.alias(别名随便起) -keypass yourpass1 -keyalg RSA -keysize 2048 -validity 3650 -keystore D:/keys/keystore.keystore -storepass yourpass2
将生成的keystore.p12或者keystore.keystore拷贝到项目resources目录下
2、配置入口文件
@SpringBootApplication
public class WandeTestSslApplication {undefined
public static void main(String[] args) {undefined
SpringApplication.run(WandeTestSslApplication.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");
connector.setScheme("http");
connector.setSecure(false);
connector.setPort(8080);
connector.setRedirectPort(8443);
return connector;
}
}
3、配置application.yml文件
server:
port: 8443
ssl:
# 证书名字
key-store: classpath:keystore.p12
#key-store: classpath:keystore.keystore
# 密钥库密码
key-store-password: yourpass2
#key-password: yourpass1 #springboot2.0不需要配置这个 T-T
key-store-type: PKCS12
key-alias: your.alias
|