application.yml配置文件
server:
port: 8443
tomcat:
max-threads: 800
accept-count: 30000
min-spare-threads: 20
max-connections: 30000
servlet-path: /ssl-server
ssl:
# 证书路径
key-store: keyTomcat.keystore
key-store-type: JKS
key-alias: tomcat
# 配置密码,就是在生成证书的时候输入的密码
key-store-password: 123456
trust-store: trustTomcat.keystore
trust-store-password: 123456
trust-store-type: JKS
trust-store-provider: SUN
client-auth: need
配置代码
/**
* it's for set http url auto change to https
*/
@Bean
public TomcatServletWebServerFactory servletContainer(){
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(){
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint=new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");//confidential
SecurityCollection collection=new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(httpConnector());
return tomcat;
}
@Bean
public Connector httpConnector(){
Connector connector=new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(8080);
connector.setSecure(false);
connector.setRedirectPort(8443);
return connector;
}