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;
        }
        
    }
  • 相关阅读:
    Delphi7 (第一天:类的编写)
    设计模式(二)Abstract Factory
    hdu 3335(最小路径覆盖)
    hdu 2236(最大匹配+枚举上下界)
    hdu 2819(二分匹配)
    hdu 3861(缩点+最小路径覆盖)
    hdu 2831(贪心)
    hdu 4296(贪心)
    hdu 2354(bfs求最短路)
    hdu 4313(类似于kruskal)
  • 原文地址:https://www.cnblogs.com/remember-forget/p/11812069.html
Copyright © 2011-2022 走看看