spring boot之支持http和https並行(http不跳轉)
阿新 • • 發佈:2019-03-11
http1 rri urn https ddp -s RoCE pro nbsp
首先需要去做個證書
yml配置文件中設置的是https監聽端口
server:
port: 10007
tomcat:
basedir: /data/apps/temp
#配置SSL
ssl:
key-store: classpath:bdcourtyard.com.jks
key-store-password: 4a98pp121wv
keyStoreType: JKS
以下是啟動類添加的代碼
/** * it‘s for set http url auto change to https*/ @Bean public TomcatEmbeddedServletContainerFactory servletContainer() { TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() { @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(9000); connector.setSecure(true); connector.setRedirectPort(10007); return connector; }
這個是同事配的,實測有效搬過來具體自己還沒研究
spring boot之支持http和https並行(http不跳轉)