溫馨提示×

后端服務(wù)器如何映射https

九三
244
2021-03-01 18:47:19
欄目: 云計算

后端服務(wù)器如何映射https

在后端服務(wù)器中設(shè)置映射https,具體方法如下:

public class Http2HttpsConfig {

/**

* 配置服務(wù)器容器

*/

@Bean

public EmbeddedServletContainerFactory servletContainer(){

TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(){

@Override

protected void postProcessContext(Context context) {

SecurityConstraint securityConstraint = new SecurityConstraint();

securityConstraint.setUserConstraint("CONFIDENTIAL");

SecurityCollection securityCollection = new SecurityCollection();

securityCollection.addPattern("/*");

securityConstraint.addCollection(securityCollection);

context.addConstraint(securityConstraint);

}

};

tomcat.addAdditionalTomcatConnectors(httpConnector());

return tomcat;

}

/**

* 設(shè)置http到https的url映射

*/

@Bean

public Connector httpConnector(){

Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");

connector.setScheme("http");

connector.setPort(8080);

connector.setSecure(false);

connector.setRedirectPort(8088);

return connector;

}

}

0