有没有一种方法可以运行Spring Boot应用程序(可运行的war),以便它在两个端口上侦听-一个带有SSL,一个没有SSL。我正在使用嵌入式Tomcat 8。
SSL当前使用
@Bean @Profile('tls') EmbeddedServletContainerCustomizer servletContainerCustomizer () throws Exception { new EmbeddedServletContainerCustomizer () { @Override public void customize (ConfigurableEmbeddedServletContainer container) { TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container tomcat.addConnectorCustomizers ( new TomcatConnectorCustomizer () { @Override public void customize (Connector connector) { connector.setPort (Integer.parseInt (retrieveRequiredSpringProperty ('ssl.connection.port'))) connector.setSecure (true) connector.setScheme ('https') connector.setProtocol (retrieveSpringPropertyOrSpecified ('ssl.connection.protocol', 'HTTP/1.1')) Http11NioProtocol proto = (Http11NioProtocol) connector.getProtocolHandler () proto.setSSLEnabled (true) proto.setKeystoreFile (retrieveRequiredSpringProperty ('ssl.protocol.keystore.file')) proto.setKeystorePass (retrieveRequiredSpringProperty ('ssl.protocol.keystore.password')) proto.setKeyPass (retrieveSpringPropertyOrSpecified ('ssl.protocol.keystore.cert.password', null)) proto.setKeystoreType ('JKS') proto.setKeyAlias (retrieveRequiredSpringProperty ('ssl.protocol.keystore.cert.name')) proto.setSslProtocol ('TLS') proto.setClientAuth ('false') } } ) } } }
我曾尝试使用Multiple,TomcatConnectorCustomizer但列出的最后一个似乎覆盖而不是累加。
TomcatConnectorCustomizer
一如既往的欢迎任何建议!
一个TomcatConnectorCustomizer只修改现有的Connector(在名称线索)。要添加其他连接器,您只需要一个不同的API(例如此处的示例),例如(从示例中复制):
Connector
@Bean public EmbeddedServletContainerFactory servletContainer() { TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(); tomcat.addAdditionalTomcatConnectors(createConnector()); return tomcat; }