最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

springboot如何將http轉(zhuǎn)https

 更新時(shí)間:2023年04月01日 09:05:41   作者:林鳥(niǎo)鳥(niǎo)  
這篇文章主要介紹了springboot如何將http轉(zhuǎn)https,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

springboot http轉(zhuǎn)https

一、安全證書(shū)的生成

可以使用jdk自帶的證書(shū)生成工具,jdk自帶一個(gè)叫keytool的證書(shū)管理工具,可以用它來(lái)實(shí)現(xiàn)簽名的證書(shū)。

1、進(jìn)入cmd命令控制終端

2、生成一個(gè)證書(shū)
別名:alias = tomcat
密碼:keypass = 123456
生成位置:keystore = D:/keys
keys文件夾需要自己先創(chuàng)建好

cmd命令:

keytool -genkey -alias tomcat -keypass 123456 -keyalg RSA -keysize 1024 -validity 365 -keystore D:/keys/tomcat.keystore -storepass 123456
 

 3、獲取tomcat.keystore文件,放入項(xiàng)目根目錄下面

 二,配置yml文件

server:
  port: 8443
  ssl:
    key-store: server.keystore
    key-alias: tomcat
    enabled: true
    key-store-type: JKS
    key-store-password: 123456

三、springbootApplication啟動(dòng)類配置

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.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
 
@SpringBootApplication
public class WeijingApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(WeijingApplication.class, args);
    }
    @Bean
    public ServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
            @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(redirectConnector());
        return tomcat;
    }
 
    private Connector redirectConnector() {
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        connector.setPort(8080);
        connector.setSecure(false);
        connector.setRedirectPort(8443);
        return connector;
    }

啟動(dòng)成功

另外:springboot2.xx版本以上可以用上面的方法 如果2.xx以下的 就要換成

EmbeddedServletContainerFactory

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.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
 
@SpringBootApplication
public class WeijingApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(WeijingApplication.class, args);
    }
    @Bean
    public EmbeddedServletContainerFactory servletContainer() {
        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
            @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)聽(tīng)的http的端口號(hào)
        connector.setPort(8080);
        connector.setSecure(false);
        //監(jiān)聽(tīng)到http的端口號(hào)后轉(zhuǎn)向到的https的端口號(hào)
        connector.setRedirectPort(8443);
        return connector;
    }

另外:報(bào)錯(cuò)端口被占用的話可以看下這個(gè)

報(bào)錯(cuò)是因?yàn)椴荒茏x取配置文件的端口,那個(gè)端口是要被用的

部署到Linux服務(wù)器 https啟動(dòng)失敗報(bào)錯(cuò) 原因:

部署到服務(wù)器的時(shí)候 需要用再linux服務(wù)器上面 重新用Linux的JDK生成證書(shū) (不能用windows生成的證書(shū)) 并放再固定的文件夾位置

更改yml文件配置 

 更改成服務(wù)器文件夾路徑:/usr/local/xxx/server.keystore

到此這篇關(guān)于springboot如何將http轉(zhuǎn)https的文章就介紹到這了,更多相關(guān)springboot http轉(zhuǎn)https內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳談Java多線程的幾個(gè)常用關(guān)鍵字

    詳談Java多線程的幾個(gè)常用關(guān)鍵字

    下面小編就為大家?guī)?lái)一篇詳談Java多線程的幾個(gè)常用關(guān)鍵字。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-04-04
  • Java優(yōu)先隊(duì)列的創(chuàng)建與使用詳解

    Java優(yōu)先隊(duì)列的創(chuàng)建與使用詳解

    這篇文章主要介紹了Java優(yōu)先隊(duì)列的創(chuàng)建與使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • SpringBoot初步連接redis詳解

    SpringBoot初步連接redis詳解

    這篇文章主要介紹了SpringBoot初步連接redis詳解,具有一定借鑒價(jià)值,需要的朋友可以參考下。
    2017-12-12
  • Kotlin修飾符lateinit(延遲初始化)案例詳解

    Kotlin修飾符lateinit(延遲初始化)案例詳解

    這篇文章主要介紹了Kotlin修飾符lateinit(延遲初始化)案例詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • Java+opencv3.2.0實(shí)現(xiàn)hough直線檢測(cè)

    Java+opencv3.2.0實(shí)現(xiàn)hough直線檢測(cè)

    這篇文章主要為大家詳細(xì)介紹了Java+opencv3.2.0之hough直線檢測(cè),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • MyBatis-Plus 樂(lè)觀鎖的具體實(shí)現(xiàn)

    MyBatis-Plus 樂(lè)觀鎖的具體實(shí)現(xiàn)

    MyBatis-Plus 的樂(lè)觀鎖通過(guò)簡(jiǎn)單的配置和注解,可以輕松實(shí)現(xiàn)高并發(fā)場(chǎng)景下的數(shù)據(jù)并發(fā)控制,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-09-09
  • 微信公眾號(hào) 網(wǎng)頁(yè)授權(quán)登錄及code been used解決詳解

    微信公眾號(hào) 網(wǎng)頁(yè)授權(quán)登錄及code been used解決詳解

    這篇文章主要介紹了微信公眾號(hào) 網(wǎng)頁(yè)授權(quán)登錄及code been used解決詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • Java檢測(cè)死鎖案例

    Java檢測(cè)死鎖案例

    這篇文章主要介紹了Java檢測(cè)死鎖案例,本文列舉了導(dǎo)致死鎖的程序,通過(guò)使用jconsole工具進(jìn)行檢測(cè)等,講述了避免死鎖的方法,需要的朋友可以參考下
    2021-07-07
  • mybatis返回的map結(jié)果如何設(shè)置有序

    mybatis返回的map結(jié)果如何設(shè)置有序

    這篇文章主要介紹了mybatis返回的map結(jié)果如何設(shè)置有序,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • Java ForkJoin框架的原理及用法

    Java ForkJoin框架的原理及用法

    這篇文章主要介紹了Java ForkJoin框架的原理及用法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-10-10

最新評(píng)論

临沭县| 南澳县| 岢岚县| 永昌县| 临沧市| 望城县| 房产| 诸城市| 琼结县| 海门市| 井研县| 维西| 淮阳县| 荔波县| 克什克腾旗| 乌拉特前旗| 永川市| 微博| 龙南县| 鱼台县| 驻马店市| 涞水县| 于田县| 油尖旺区| 汾西县| 黄大仙区| 米脂县| 临漳县| 宜川县| 蓬溪县| 平江县| 七台河市| 滁州市| 峨眉山市| 商城县| 张家口市| 万全县| 金堂县| 中阳县| 云南省| 西丰县|