Java Spring Security不会将HTTP重定向到HTTPS

Java Spring Security不会将HTTP重定向到HTTPS,java,spring,tomcat,ssl,spring-security,Java,Spring,Tomcat,Ssl,Spring Security,我正在使用Spring4和Tomcat7实现一个web应用程序 我使用SSL证书在Tomcat上运行应用程序,它工作正常,但我想强制任何HTTP请求重定向到其HTTPS请求 我搜索了Spring Security并添加了一些配置,如下所示: @配置 @启用Web安全性 @EnableGlobalMethodSecurity(securedEnabled=true,Prespenabled=true,proxyTargetClass=true) 公共类CoreSecurityConfig扩展了We

我正在使用Spring4和Tomcat7实现一个web应用程序

我使用SSL证书在Tomcat上运行应用程序,它工作正常,但我想强制任何HTTP请求重定向到其HTTPS请求

我搜索了Spring Security并添加了一些配置,如下所示:

@配置
@启用Web安全性
@EnableGlobalMethodSecurity(securedEnabled=true,Prespenabled=true,proxyTargetClass=true)
公共类CoreSecurityConfig扩展了WebSecurity配置适配器{
@凌驾
受保护的无效配置(HttpSecurity http)引发异常{
http
.antMatcher(“/**”)
.requireChannel()
.anyRequest().requirescure();
http
.antMatcher(“/**”)
.portMapper()
.http(80).mapsTo(443);
}
}
但它似乎工作不正常,SpringSecurity也没有执行重定向

这个配置有问题吗?

多亏了,通过将重定向配置添加到Tomcat的
web.xml
,Tomcat实现了重定向


我的申请
/*
保密的

您可以尝试添加
http.headers().httpStrictTransportSecurity()
来告诉客户端他们需要使用HTTPS。@ngreen我将重定向配置添加到tomcat web.xml,效果很好。无论如何,谢谢你的帮助。嗨@BabakBehzadi,这个解决方案有效,谢谢!如果您理解HttpSecurity端口映射器不工作的原因(根据您的问题),请分享,因为它对我也不工作,我很想了解原因。