我在这里有解决方案:
http .authenticationEntryPoint(authenticationEntryPoint)
AuthenticationEntryPoint源代码:
@Componentpublic class Http401UnauthorizedEntryPoint implements AuthenticationEntryPoint { private final Logger log = LoggerFactory.getLogger(Http401UnauthorizedEntryPoint.class); @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException arg2) throws IOException, ServletException { log.debug("Pre-authenticated entry point called. Rejecting access"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied"); }}


