title: Failed to add persistent remember me to Spring application
body: <p>I followed <a href="http://javasampleapproach.com/spring-framework/spring-security/configure-persistent-token-remember-me-authentication-persistent-token-approach-spring-boot" rel="nofollow noreferrer">this guide</a> to setup a Remember Me mechanism on my Spring Boot 2 application, without success. Even if I check the remember me checkbox at login, no remember me cookie is generated. No exception is thrown.</p>
  
  <p>This is my SecurityConfiguration.java:</p>
  
  <pre><code>import javax.sql.DataSource;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  import org.springframework.security.config.annotation.web.builders.WebSecurity;
  import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
  import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;
  import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;
  
  import it.niuma.cse.service.UserDetailsServiceImp;
  
  @Configuration
  @EnableWebSecurity
  public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  
      @Autowired
      public UserDetailsServiceImp  userDetailsService;
  
      @Autowired
      DataSource dataSource;
  
       @Bean
          public BCryptPasswordEncoder passwordEncoder() {
              BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
              return bCryptPasswordEncoder;
          }
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth)
              throws Exception {
          auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
           http.csrf().disable();
          http.authorizeRequests().antMatchers("/", "/loginMe", "/logout").permitAll()
          .antMatchers("/fornitore/**").hasRole("USER")
          .antMatchers("/ruolo/**").hasRole("ADMIN")
          .anyRequest().authenticated();
  
          http.authorizeRequests().and().exceptionHandling().accessDeniedPage("/accessDenied");
  
          http.authorizeRequests().and().formLogin()//
           // Submit URL of login page.
          .loginProcessingUrl("/j_spring_security_check") // Submit URL
          .loginPage("/loginMe")//
          .defaultSuccessUrl("/loginOK")//
          .failureUrl("/loginMe?error=true")//
          .usernameParameter("username")//
          .passwordParameter("password")
           // Config for Logout Page
          .and()
          .rememberMe()
              .rememberMeCookieName("remember-me")
              .tokenValiditySeconds(24 * 60 * 60)
              .tokenRepository(persistentTokenRepository())
           .and().logout().logoutUrl("/logout").logoutSuccessUrl("/loginMe");
      }
  
      @Bean
      public PersistentTokenRepository persistentTokenRepository() {
          JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl();
          tokenRepository.setDataSource(dataSource);
          return tokenRepository;
      }
  
      @Override
      public void configure(WebSecurity web) throws Exception {
          web.ignoring().antMatchers("/resources/**", "/assets/**", "/css/**", "/js/**", "/img/**", "/plugins/**" , "/i18n/**");
      }
  }
  </code></pre>