基于springboot設(shè)置Https請求過程解析
1.首先去阿里云購買個證書,也有免費的,但是免費的只能使用一年,證書需要綁定域名
2.將證書放進項目
3.配置YML
server: ssl: key-store: 55555.pfx key-store-password: 55555 keyStoreType: PKCS12 connectionTimeout: 20000 port: 8888
重點來了,配置請求轉(zhuǎn)發(fā)
@Configuration public class WebMvcconfig implements WebMvcConfigurer { @Bean public TomcatServletWebServerFactory servletContainer() { TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() { @Override protected void postProcessContext(Context context) { SecurityConstraint constraint = new SecurityConstraint(); constraint.setUserConstraint("CONFIDENTIAL"); SecurityCollection collection = new SecurityCollection(); collection.addPattern("/*"); constraint.addCollection(collection); context.addConstraint(constraint); } }; tomcat.addAdditionalTomcatConnectors(httpConnector()); return tomcat; } @Bean public Connector httpConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("http"); // Connector監(jiān)聽的http的端口號 connector.setPort(8080); connector.setSecure(false); // 監(jiān)聽到http的端口號后轉(zhuǎn)向到的https的端口號 connector.setRedirectPort(8888); return connector; } }
如果請求報錯:java.lang.UnsatisfiedLinkError: org.apache.tomcat.jni.SSL.renegotiatePending(J)I問題
在pom.xml中加入
<properties> <tomcat.version>9.0.12</tomcat.version> </properties>
<dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-juli</artifactId> <version>${tomcat.version}</version> </dependency>
然后運行,請求成功!
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- SpringBoot 改造成https訪問的實現(xiàn)
- Springboot單體架構(gòu)http請求轉(zhuǎn)換https請求來支持微信小程序調(diào)用接口
- SpringBoot配置https實操方法
- springboot+nginx+https+linux實現(xiàn)負載均衡加域名訪問簡單測試
- springboot配置https訪問的方法
- SpringBoot2.0如何啟用https協(xié)議
- springboot添加https服務(wù)器的方法
- 詳解SpringBoot初始教程之Tomcat、Https配置以及Jetty優(yōu)化
- 為SpringBoot服務(wù)添加HTTPS證書的方法
相關(guān)文章
Java+swing+Mysql實現(xiàn)商品銷售管理系統(tǒng)
基礎(chǔ)扎不扎實只有在實戰(zhàn)中才能顯現(xiàn),本篇文章手把手帶你用Java+swing+Mysql實現(xiàn)商品銷售管理系統(tǒng),大家可以在過程中查缺補漏,提升水平2022-01-01SpringBoot 整合 dubbo xml實現(xiàn)代碼示例
這篇文章主要介紹了SpringBoot 整合 dubbo xml實現(xiàn)代碼示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03JSON復(fù)雜數(shù)據(jù)處理之Json樹形結(jié)構(gòu)數(shù)據(jù)轉(zhuǎn)Java對象并存儲到數(shù)據(jù)庫的實現(xiàn)
這篇文章主要介紹了JSON復(fù)雜數(shù)據(jù)處理之Json樹形結(jié)構(gòu)數(shù)據(jù)轉(zhuǎn)Java對象并存儲到數(shù)據(jù)庫的實現(xiàn)的相關(guān)資料,需要的朋友可以參考下2016-03-03在SpringBoot項目中使用JetCache緩存的詳細教程
Spring Boot是一個非常流行的Java開發(fā)框架,JetCache是一個基于注解的高性能緩存框架,本文將介紹如何在Spring Boot項目中使用JetCache緩存,并提供一個詳細案例來說明如何配置和使用JetCache,需要的朋友可以參考下2024-06-06spring cloud-給Eureka Server加上安全的用戶認證詳解
這篇文章主要介紹了spring cloud-給Eureka Server加上安全的用戶認證詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-01-01