For further reference, please consider the following sections:
自己生成的证书浏览器会有危险提示,去ssl网站上使用金钱申请则不会
server:
ssl:
# 证书路径
key-store: spring-boot-demo-https\src\main\resources\server.keystore
key-alias: tomcat
enabled: true
key-store-type: JKS
#与申请时输入一致
key-store-password: 123456
# 浏览器默认端口 和 80 类似
port: 443
#debug: true
@Bean
public Connector connector(){
Connector connector=new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(80);
connector.setSecure(false);
connector.setRedirectPort(443);
return connector;
}
@Bean
public TomcatServletWebServerFactory tomcatServletWebServerFactory(Connector connector){
TomcatServletWebServerFactory tomcat=new TomcatServletWebServerFactory(){
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint=new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection=new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(connector);
return tomcat;
}