2016-09-21 77 views
1

我使用春季啓動框架發展與Web應用程序嵌入式的Tomcat。需要爲多個端口獲得一些https連接。春季啓動 - 創建HTTPS連接不起作用

爲此,我使用SpringApplicationBuilder,像這樣的位置:

SpringApplicationBuilder parentBuilder 
      = new SpringApplicationBuilder(ApplicationConfiguration.class); 

    parentBuilder.child(WithoutClientAuth.class) 
      .properties("server.port:8443") 
      .properties("security.require_ssl=true") 
      .properties("ssl.key-store=server.jks") 
      .properties("ssl.key-store-password=password") 
      .properties("ssl.key-password=password") 
      .run(args); 

    parentBuilder.child(WithClientAuth.class) 
      .properties("server.port:9443") 
      .properties("security.require_ssl=true") 
      .properties("ssl.key-store=server.jks") 
      .properties("ssl.key-store-password=password") 
      .properties("ssl.key-password=password") 
      .run(args); 

但是,啓動應用程序後,通信協議是不安全的。能夠看到輸出中:

TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 9443 (http) 
StandardService    : Starting service Tomcat 
StandardEngine     : Starting Servlet Engine: Apache Tomcat/8.5.4 

您有想法以這種方式獲得安全通信嗎?

回答

1

您用於SSL配置的屬性是錯誤的。它們應該全部以前綴server.

parentBuilder.child(WithoutClientAuth.class) 
     .properties("server.port:8443") 
     .properties("security.require_ssl=true") 
     .properties("server.ssl.key-store=server.jks") 
     .properties("server.ssl.key-store-password=password") 
     .properties("server.ssl.key-password=password") 
     .run(args);