SpringCloud踩坑日记 - zuul开启https


    springboot项目jar包方式启动通用

 

  1.证书放入资源文件夹

  

 

   2.server 添加 ssl配置

  

       踩坑点: key-store: classpath后面的冒号需要紧跟着classpath,不能有空格,  这里我折腾了1个小时多才发现

   

     3.  原有http访问跳转到https

    

   @Bean
    public Connector connector(){
      
     //此函数中的80、443端口仅测试使用。 实际情况可读取配置后修改 
     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; }

  

 

     

       

 

 

 

 

 

  

  

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM