上一篇:https://blog.csdn.net/fengxianaa/article/details/124697101
5. 自定义登录页面
1. 准备登陆页面
static.zip地址:springsecurity学习使用的静态文件-Java文档类资源-CSDN下载
这个 static.zip 解压后是这样子的
里面的 login.html 就是我们的登陆页面
把 static 文件夹复制到 项目中的 resource 文件夹下
2. 修改 SecurityConfig
让 SecurityConfig 继承 WebSecurityConfigurerAdapter
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
@Override
public void configure(WebSecurity web) throws Exception {
// 静态资源不用验证
web.ignoring().antMatchers("/js
@Bean
public JdbcTokenRepositoryImpl jdbcTokenRepositoryImpl() {
JdbcTokenRepositoryImpl persistentTokenRepository = new JdbcTokenRepositoryImpl();
persistentTokenRepository.setDataSource(dataSource);
return persistentTokenRepository;
}
//configure 方法 增加
http.rememberMe()
.tokenRepository(jdbcTokenRepositoryImpl()) // 配置token持久化仓库
// .tokenValiditySeconds(3600) // 过期时间,单位为秒
.userDetailsService(loginUserService); // 处理自动登录逻辑
登录成功后,数据库中的token
这样关闭浏览器后,再次访问就不用登录了



