美文网首页
SpringBoot2 http转https

SpringBoot2 http转https

作者: 乐逍遥_bbc1 | 来源:发表于2018-03-08 18:40 被阅读0次

    在SpringBoot1.5的http转https见:

    https://www.cnblogs.com/xxt19970908/p/6736370.html

    升级到SpringBoot2.0发现报错。解决方案如下:

    完整的代码在github

    //Srping2.0的转换代码

    @Bean

    public ServletWebServerFactory serletContainer(){

    TomcatServletWebServerFactory tomcat=new TomcatServletWebServerFactory(){

    @Override

            protected void postProcessContext(Context context) {

    SecurityConstraint constraint =new SecurityConstraint();

    constraint.setUserConstraint("CONFIDENTIAL");

    SecurityCollection collection =new SecurityCollection();

    collection.addPattern("/*");

    constraint.addCollection(collection);

    context.addConstraint(constraint);

    }

    };

    tomcat.addAdditionalTomcatConnectors(httpConnector());

    return tomcat;

    }

    这样就可以解决  Springboot2 http自动跳转到https,实现了自动转向功能,利用tomcat的redirect功能,进行http到https的redirect.

    原因是Springboot2取消了EmbeddedServletContainerFactory  TomcatEmbeddedServletContainerFactory

    相关文章

      网友评论

          本文标题:SpringBoot2 http转https

          本文链接:https://www.haomeiwen.com/subject/jrzrfftx.html