Controller类通常用于根据业务逻辑重定向应用程序流。 控制器中的大部分方法都标有@RequestMapping注释,即使您能够从服务调用控制器方法,它也无法实现目的,因为Controller的返回类型是特定的视图。 您必须编写AuthenticationFailureHandler的实现来实现该功能。 这可以通过弹簧安全性轻松实现
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;
@Component
public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler{
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception) throws IOException, ServletException {