參考地址
https://blog.csdn.net/qq_45848700/article/details/122319021
在自定義SpringSecurity捕獲的異常,發現配置生效了,但是就是沒有進行捕捉,通過打印控制台后發現,異常被全局異常處理器給捕獲了,並且直接return返回了
//配置異常處理器
http.exceptionHandling()
.authenticationEntryPoint(authenticationEntryPoint)
.accessDeniedHandler(accessDeniedHandler);
解決方法,在全局異常處理器中把改異常拋出
/**
* SpringSecurity拋出異常但AccessDeniedHandler不生效
* 全局異常中捕獲AccessDeniedException再拋出就可以被AccessDeniedHandler捕獲到了
* @param e
* @throws AccessDeniedException
*/
@ExceptionHandler(AccessDeniedException.class)
public void accessDeniedException(AccessDeniedException e) throws AccessDeniedException {
throw e;
}
