首页 > 解决方案 > Spring Boot 启用 HTTPS

问题描述

我正在使用 Spring Boot 2.3 来创建微服务。我需要启用 HTTPS 并禁用 HTTP 调用。我有 .pfx 格式的证书。我从https://www.thomasvitale.com/https-spring-boot-ssl-certificate/尝试了以下步骤

server.port=8443

server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:mycert.pfx
server.ssl.key-store-password=password
security.require-ssl=true

由于我们使用的是 Spring Boot 安全性,因此也添加了以下行,

   http
        .requiresChannel()
        .anyRequest()
        .requiresSecure();

在 WebSecurityConfigurerAdapter 的配置方法中。但是通过这些配置,我可以获得 HTTP 和 HTTPS 的响应。所以我不确定 HTTPS 是否真的像我配置的 requiressecure 那样工作,但它不工作。在密钥库属性中提及 pfx 文件是否正确?

标签: javaspring-bootsslspring-security

解决方案


推荐阅读