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;
        }
        
    }
  • 相关阅读:
    SNMP概述–运维必知的协议基础
    关于多线程情况下Net-SNMP v3 版本导致进程假死情况的跟踪与分析
    关于snmp octet string和普通string问题
    SVN状态说明
    SNMP mib文件说明
    Linux之 proc文件系统
    django .all .values .value_list 数据库获取数据
    Django form验证
    JSONP实现
    iframe和form表单实现ajax请求上传数据
  • 原文地址:https://www.cnblogs.com/remember-forget/p/11812069.html
Copyright © 2011-2022 走看看