Spring boot http, https
Posted 1161588342
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring boot http, https相关的知识,希望对你有一定的参考价值。
1:同时支持http, https配置
参考文献: https://www.cnblogs.com/lianggp/p/8136540.html
2:http 转发到 https配置
@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 TomcatEmbeddedServletContainerFactory tomcatServletWebServerFactory(Connector connector){ TomcatEmbeddedServletContainerFactory tomcat=new TomcatEmbeddedServletContainerFactory (){ @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; }
以上是关于Spring boot http, https的主要内容,如果未能解决你的问题,请参考以下文章
Spring Boot工程支持HTTP和HTTPS,HTTP重定向HTTPS