参见Spring Security Reference:
虽然自动生成的登录页面便于快速启动和运行,但是大多数应用程序都希望提供自己的登录页面。为此,我们可以如下所示更新配置:
protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") 1 .permitAll(); 2}1 更新的配置指定登录页面的位置。
2
我们必须授予所有用户(即未经身份验证的用户)访问我们登录页面的权限。formLogin()。permitAll()方法允许向所有用户授予与基于表单的登录相关联的所有URL的访问权限。
您修改的代码:
public void configure(HttpSecurity httpSecurity) throws Exception { httpSecurity .authorizeRequests() .antMatchers("/home*").hasRole("USER") .and() .formLogin() .loginPage("/login.html") .permitAll();}


