Spring boot 如何在spring boot 2中配置https?
我已使用Spring boot 如何在spring boot 2中配置https?,spring-boot,spring-security,Spring Boot,Spring Security,我已使用keytool生成了自签名证书。我已添加到我的资源文件夹中。 在我的应用程序.properties中,我添加了 security.require-ssl=true # The format used for the keystore server.ssl.key-store-type=PKCS12 # The path to the keystore containing the certificate server.ssl.key-store=classpath:keystore.
keytool
生成了自签名证书。我已添加到我的资源文件夹中。
在我的应用程序.properties
中,我添加了
security.require-ssl=true
# The format used for the keystore
server.ssl.key-store-type=PKCS12
# The path to the keystore containing the certificate
server.ssl.key-store=classpath:keystore.p12
# The password used to generate the certificate
server.ssl.key-store-password=
# The alias mapped to the certificate
server.ssl.key-alias=tomcat
我的配置文件:
@Bean
public EmbeddedServletContainerFactory servletContainer() {
EmbeddedServletContainerFactory tomcat = new EmbeddedServletContainerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(getHttpConnector());
return tomcat;
}
但是我仍然无法使用https访问我的应用程序?在
Spring boot 2中没有EmbeddedServletContainerFactory
,而是使用TomcatServletWebServerFactory
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(getHttpConnector());
return tomcat;
}
getHttpConnector()方法在哪里?还有关于如何在SpringBoot2中实现https的更多文档吗?