1.首先从云服务器下载证书压缩包,将证书.prx文件复制到resource目录下
2.编写yml配置文件
http:
port: 8082
server:
port: 443
ssl:
key-store: classpath:xxxxxxxx.com.pfx
key-store-password: xxxxxx
keyStoreType: PKCS12
3.主启动类配置拦截
@Bean
public ServletWebServerFactory servletContainer() {
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(redirectConnector());
return tomcat;
}
private Connector redirectConnector() {
Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setScheme("http");
connector.setPort(8082);
connector.setSecure(false);
connector.setRedirectPort(443);
return connector;
}
标题