基于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í)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot?創(chuàng)建獲取yml里配置字段值
在Spring?Boot中通過@ConfigurationProperties綁定YML配置,創(chuàng)建Bean并提供訪問方法,實現(xiàn)根據(jù)配置字段動態(tài)處理業(yè)務(wù)邏輯,具有一定的參考價值,感興趣的可以了解一下2025-06-06
詳解Java接口簽名(Signature)實現(xiàn)方案
這篇文章主要介紹了Java接口簽名(Signature)實現(xiàn)方案?,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-01-01
SpringBoot導(dǎo)出Excel表格到指定路徑的代碼詳解
Spring Boot導(dǎo)出Excel通常涉及到使用第三方庫如Apache POI或者XlsxWriter等,它們能幫助你在Spring應(yīng)用中生成并下載Excel文件,那么SpringBoot如何導(dǎo)出Excel表格到指定路徑,本文將給大家詳細的介紹一下2024-07-07
Java調(diào)用DeepSeek?api實現(xiàn)方法記錄
這篇文章主要介紹了如何在Java中調(diào)用DeepSeek?API,包括在官網(wǎng)獲取APIKeys、創(chuàng)建API請求工具類以及處理返回結(jié)果的步驟,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2025-02-02
Java實現(xiàn)AOP功能的封裝與配置的小框架實例代碼
這篇文章主要介紹了Java實現(xiàn)AOP功能的封裝與配置的小框架實例代碼,分享了相關(guān)代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下2018-02-02
idea創(chuàng)建JAVA Class時自動生成頭部文檔注釋的方法
這篇文章主要介紹了idea創(chuàng)建JAVA Class時自動生成頭部文檔注釋的方法,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12

