zoukankan      html  css  js  c++  java
  • springboot 80转443

    application.yml 中配置https证书信息

     向spring容器中注入两个Bean,代码如下

    import java.util.Map;
    
    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.simpleframe.core.dao.OpenDao;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Scope;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @Scope("prototype")
    public class UserController extends  {
    
        
        @Bean
        public Connector connector(){
            Connector connector=new Connector("org.apache.coyote.http11.Http11NioProtocol");
            connector.setScheme("http");
            connector.setPort(80);
            connector.setSecure(false);
            connector.setRedirectPort(443);
            return connector;
        }
    
        @Bean
        public TomcatServletWebServerFactory tomcatServletWebServerFactory(Connector connector){
            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(connector);
            return tomcat;
        }
        
    }
  • 相关阅读:
    Python常用模块——第三方开源模块的安装使用
    Python常用模块——模块介绍与导入
    Linux文本编辑器vim
    Linux文件和文件夹的操作
    网络编程之IO模型——selectors模块
    设计模式学习(19)- 中介者模式
    设计模式学习(18)- 迭代器模式
    设计模式学习(17)- 解释器模式
    设计模式学习(16)- 命令模式
    设计模式学习(15)- 责任链模式
  • 原文地址:https://www.cnblogs.com/remember-forget/p/11812069.html
Copyright © 2011-2022 走看看