Spring Boot 配置SSL很简单,只需要通过一系列的 server.ssl.*
参数即可完成配置,如下所示。
application.properties配置文件参考配置:
server.port = 8443
server.ssl.protocol=TLS
server.ssl.key-store=classpath: javastack.keystore
server.ssl.key-store-password=javastack
server.ssl.key-store-type=JKS
这边只是提供了一个SSL单向演示的验证。更多的SSL参数配置如下:
server.ssl.ciphers= # Supported SsL ciphers.
server.ssl.client-auth= # whether client authentication is wanted ( "want" ) orneeded ( "need " ) . Requires a trust store.
server.ssl.enabled-protocols= # Enabled SSL protocols.
server.ssl.key-alias= # Alias that identifies the key in the key store.
server.ssl.key-password= # Password used to access the key in the key store.
server.ssl.key-store= # Path to the key store that holds the SsL certificate(ypically a jks file ) .
server.ssl.key-store-password= # Password used to access the key store.
server.ssl.key-store-provider= # Provider for the key store.
server.ssl.protocol=TLS # SSL protocol to use.
server.ssl.trust-store= # Trust store that holds sSL certificates.
server.ssl.trust-store-password= # Password used to access the trust store.
server.ssl.trust-store-provider= # Provider for the trust store.
server.ssl.trust-store-type= # Type of the trust store.
参数对应的类: org.springframework.boot.web.server.Ssl
上面的例子配置后就能开启HTTPS了,默认的HTTP协议就不再支持了,Spring Boot不支持以配置文件配置的方式同时支持HTTP和HTTPS。如何同时配置可以看我的另一篇文章《SpringBoot如何同时支持Http和Https》