日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

1.申請證書

這里我選擇的是阿里云的個人免費的證書

給你的項目配置個https吧

 

因為使用的是內置的Tomcat,所以下載Tomcat類型的

給你的項目配置個https吧

 

2.配置項目

將證書XXXX.pfx文件放到項目的resources目錄,接著修改Application.yml文件

server:
  port: 443
  ssl:
    key-store: classpath:XXXX.pfx
    key-store-password: 證書密碼
    keyStoreType: PKCS12

接著修改啟動類,添加如下內容,接著啟動項目

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.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
public class MxemApplication implements EmbeddedServletContainerCustomizer {
    //攔截所有請求
    @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;
    }

    //配置http轉https
    @Bean
    public Connector httpConnector() {
        Connector connector = new Connector(TomcatEmbeddedServletContainerFactory.DEFAULT_PROTOCOL);
        connector.setScheme("http");
        //Connector監聽的http的端口號
        connector.setPort(80);
        connector.setSecure(false);
        //監聽到http的端口號后轉向到的https的端口號
        connector.setRedirectPort(443);
        return connector;
    }

    //這里設置默認端口為443,即https的,如果這里不設置,會https和http爭奪80端口
    @Override
    public void customize(ConfigurableEmbeddedServletContainer container) {
        container.setPort(443);
    }
}

3.可能出現的問題

可能會出現下面的錯誤

Address already in use: bind

解決辦法

以windows系統為例,查看當前端口被哪個進程占用了(進入到CMD中)

netstat -ano|findstr "443"

然后找到進程ID,使用任務管理器結束此進程即可。

如果對你有幫助,還請點個贊,點個關注

分享到:
標簽:https
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定