spring boot 配置HTTPS代碼實例
這篇文章主要介紹了spring boot 配置HTTPS代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
spring boot 版本是<version>1.5.8.RELEASE</version>
1.配置文件里,看下不要有空格=[不要有空格]
2.別名
================
server.port=8095 server.ssl.key-store=*.pfx server.ssl.key-store-password=** server.ssl.key-store-type=PKCS12 server.ssl.key-alias=alias//別名
代碼
import org.apache.catalina.Context; import org.apache.catalina.connector.Connector; import org.apache.tomcat.util.descriptor.web.SecurityCollection; import org.apache.tomcat.util.descriptor.web.SecurityConstraint; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * 擴展: 并將 http 自動轉向 https * @Description:類說明: * @author: gzh * @date: 2019年11月1日上午11:08:20 */ @Configuration public class HttpsConfiguration { @Bean public EmbeddedServletContainerFactory servletContainer() { TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(){ 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(httpConnector()); return tomcat; } @Bean public Connector httpConnector(){ Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("http"); connector.setPort(8096); //表示用8080端口來供http訪問(PB,kingdee) connector.setSecure(false); //輸入:my.com,跳到: http:// www.my.com connector.setRedirectPort(8095); //自動重定向到8095,443端口 return connector; } }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
數(shù)組實現(xiàn)Java 自定義Queue隊列及應用操作
這篇文章主要介紹了數(shù)組實現(xiàn)Java 自定義Queue隊列及應用操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-06-06Spring WebFlux實現(xiàn)參數(shù)校驗的示例代碼
請求參數(shù)校驗,在實際的應用中很常見,網(wǎng)上的文章大部分提供的使用注解的方式做參數(shù)校驗。本文主要介紹 Spring Webflux Function Endpoint 使用 Spring Validation 來校驗請求的參數(shù)。感興趣的可以了解一下2021-08-08Spring Boot中@ConditionalOnProperty的使用方法
這篇文章主要給大家介紹了關于Spring Boot中@ConditionalOnProperty的使用方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者使用Spring Boot具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-12-12springboot HandlerIntercepter攔截器修改request body數(shù)據(jù)的操作
這篇文章主要介紹了springboot HandlerIntercepter攔截器修改request body數(shù)據(jù)的操作,具有很好的參考價值,希望對大家有所幫助。2021-06-06