title: How to redirect HTTP requests to HTTPS using Spring Security Java configuration?
body: <p>I have a Spring Security version 3.2.3 application that listens to both HTTP and HTTPS. I want any request to the HTTP port to be redirected to HTTPS. How do I configure that using Java only?</p>
  
  <p><a href="http://docs.spring.io/spring-security/site/docs/3.2.0.RC2/apidocs/org/springframework/security/config/annotation/web/builders/HttpSecurity.html#requiresChannel%28%29" rel="noreferrer">Spring Security javadoc for <code>HttpSecurity</code></a> proposes the following solution (trimmed to the essential):</p>
  
  <pre><code>public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
      protected void configure(HttpSecurity http) {
          http.channelSecurity().anyRequest().requiresSecure();
      }
  }
  </code></pre>
  
  <p>However that doesn't work because <code>HttpSecurity</code> doesn't have method <code>channelSecurity()</code>.</p>