使用jdk工具keytool生成密钥文件
keytool -genkey -alias test -keyalg RSA -keystore D:server.keystore
springboot开启https(版本2.1.6 Release)
- 将server.keystore文件拷贝到项目的resources目录下
- 配置文件增加如下内容
server:
ssl:
enabled: true
key-store: classpath:server.keystore
key-alias: test
key-store-password: 123456
key-store-type: JKS
port: 443
- 启动项目,输入https://ip 即可访问
springboot undertow 容器开启http端口8888
import io.undertow.UndertowOptions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SSLConfiguration {
@Bean
UndertowServletWebServerFactory undertowServletWebServerFactory() {
UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory();
factory.addBuilderCustomizers(
builder -> {
builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)
.setServerOption(UndertowOptions.HTTP2_SETTINGS_ENABLE_PUSH, true);
builder.addHttpListener(8888,"0.0.0.0");
});
return factory;
}
}
重启服务后,通过http://ip:8888 亦可访问