zoukankan      html  css  js  c++  java
  • spring boot 开启https

    1.生成证书

    keytool -genkey -alias tomcat -keyalg RSA -keystore E:/https.keystore
    

      

    将生成好的证书放在项目根目录即可

    2 修改配置文件

    server:
      port: 443
      servlet:
        context-path: /
      tomcat:
        uri-encoding: UTF-8
        max-threads: 1000
        min-spare-threads: 30
      ssl:
        #生成证书的名字
        key-store: https.keystore
        #密钥库密码
        key-store-password: 123456
        key-store-type: JKS
        key-alias: tomcat
    

     3 开启访问80端口跳转433端口

    package com.yjkj.repository;
    
    import org.apache.catalina.connector.Connector;
    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.boot.web.servlet.support.SpringBootServletInitializer;
    import org.springframework.context.annotation.Bean;
    
    @SpringBootApplication
    public class RepositoryApplication extends SpringBootServletInitializer {
    
        public static void main(String[] args) {
            SpringApplication.run(RepositoryApplication.class, args);
        }
    
        @Bean
        public ServletWebServerFactory servletContainer() {
            TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
            tomcat.addAdditionalTomcatConnectors(createHTTPConnector());
            return tomcat;
        }
    
        private Connector createHTTPConnector() {
            Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
            //同时启用http(80)、https(8443)两个端口
            connector.setScheme("http");
            connector.setSecure(false);
            connector.setPort(80);
            connector.setRedirectPort(443);
            return connector;
        }
    }

    https访问

      

    http访问

  • 相关阅读:
    {Notes}{Latex}{multirow}
    [Reship] Mean Shift 算法介绍
    {Notes}{LaTeX}{enumerate}
    This is a test.
    js中的执行环境和作用域链
    js的预解析
    js笔试题一套(未完待续)
    使用setTimeout 来实现setInterval的效果
    ie6 ie7下报脚本错误"Expected identifier, string or number" 的原因和解决方法
    【雕爷学编程】Arduino动手做(63)---TCS3200D颜色识别传感器
  • 原文地址:https://www.cnblogs.com/joyny/p/11309584.html
Copyright © 2011-2022 走看看