码迷,mamicode.com
首页 > 编程语言 > 详细

spring boot之支持http和https并行(http不跳转)

时间:2019-03-11 13:28:49      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:image   factor   监听端口   ssl   研究   跳转   factory   png   mbed   

 

首先需要去做个证书

技术图片

 

yml配置文件中设置的是https监听端口

server:
  port: 10007
  tomcat:
    basedir: /data/apps/temp
    #配置SSL
  ssl:
    key-store: classpath:bdcourtyard.com.jks
    key-store-password: 4a98pp121wv
    keyStoreType: JKS

 

以下是启动类添加的代码

 /**
     * it‘s for set http url auto change to https
     */
    @Bean
    public TomcatEmbeddedServletContainerFactory servletContainer() {
        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
            @Override
            protected void postProcessContext(Context context) {
                SecurityConstraint securityConstraint = new SecurityConstraint();
                securityConstraint.setUserConstraint("CONFIDENTIAL");//confidential
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                securityConstraint.addCollection(collection);
                context.addConstraint(securityConstraint);
            }
        };
        tomcat.addAdditionalTomcatConnectors(httpConnector());
        return tomcat;
    }

    @Bean
    public Connector httpConnector() {
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        connector.setPort(9000);
        connector.setSecure(true);
        connector.setRedirectPort(10007);
        return connector;
    }

 

这个是同事配的,实测有效搬过来具体自己还没研究

 

spring boot之支持http和https并行(http不跳转)

标签:image   factor   监听端口   ssl   研究   跳转   factory   png   mbed   

原文地址:https://www.cnblogs.com/heroinss/p/10509739.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!