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