试试这个:
@Overridepublic void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { // ....... response.sendRedirect("/login.html?error=fail"); }更新:
将“ /login.html?error=fail”添加到authorizeRequests()部分非常重要,否则控制器将不会选择error参数。
替换
.antMatchers("/login").permitAll()为 .antMatchers("/login**").permitAll()


