春季过滤器异常处理 [英] exception handling for filter in spring
问题描述
一切正常工作正常。
现在我有一个过滤器(是的,不是拦截器,以处理某些要求),这是使用DelegatingFilterProxy和ContextLoaderListener实现的。
当我从上面的过滤器中抛出相同的异常时,它没有捕捉到在控制器案例中完成的方式。
$ b
这里有什么问题?
p>过滤器发生在控制器均匀解决之前,因此从过滤器抛出的异常不能被控制器建议捕获。
过滤器是servlet的一部分,而不是真正的MVC堆栈。
I am handling exceptions in spring using @ExceptionHandler. Any exception thrown by controller is caught using method annotated with @ExceptionHandler and action is taken accordingly. To avoid writing @exceptionHandler for every controller i am using @ControllerAdvice annotation.
Everything works fine as expected.
Now i have a filter(Yes, not interceptor, to handle certain requirement) which is implemented using DelegatingFilterProxy and ContextLoaderListener.
When i am throwing the same exception from above filter, its not caught the way it was done in controller case. It is directly thrown to user.
What's wrong in here?
Filters happens before controllers are even resolved so exceptions thrown from filters can't be caught by a Controller Advice.
Filters are a part of the servlet and not really the MVC stack.
这篇关于春季过滤器异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!