|
22 | 22 | import org.springframework.lang.Nullable;
|
23 | 23 | import org.springframework.web.method.HandlerMethod;
|
24 | 24 | import org.springframework.web.servlet.ModelAndView;
|
25 |
| -import org.springframework.web.servlet.function.HandlerFunction; |
26 | 25 |
|
27 | 26 | /**
|
28 | 27 | * Abstract base class for
|
29 | 28 | * {@link org.springframework.web.servlet.HandlerExceptionResolver HandlerExceptionResolver}
|
30 | 29 | * implementations that support handling exceptions from handlers of type {@link HandlerMethod}.
|
31 | 30 | *
|
32 | 31 | * @author Rossen Stoyanchev
|
| 32 | + * @author Juergen Hoeller |
33 | 33 | * @since 3.1
|
34 | 34 | */
|
35 | 35 | public abstract class AbstractHandlerMethodExceptionResolver extends AbstractHandlerExceptionResolver {
|
36 | 36 |
|
37 | 37 | /**
|
38 |
| - * Checks if the handler is a {@link HandlerMethod} or a {@link HandlerFunction} |
39 |
| - * and then delegates to the base class implementation of {@code #shouldApplyTo(HttpServletRequest, Object)} |
40 |
| - * passing the bean of the {@code HandlerMethod}. Otherwise, returns {@code false}. |
| 38 | + * Checks if the handler is a {@link HandlerMethod} or the resolver has global exception |
| 39 | + * handlers and then delegates to the base class implementation of {@code #shouldApplyTo} |
| 40 | + * passing the bean of the {@code HandlerMethod} if necessary. Otherwise, returns {@code false}. |
| 41 | + * @see HandlerMethod |
| 42 | + * @see #hasGlobalExceptionHandlers() |
41 | 43 | */
|
42 | 44 | @Override
|
43 | 45 | protected boolean shouldApplyTo(HttpServletRequest request, @Nullable Object handler) {
|
44 |
| - if (handler == null) { |
45 |
| - return super.shouldApplyTo(request, null); |
| 46 | + if (handler instanceof HandlerMethod handlerMethod) { |
| 47 | + return super.shouldApplyTo(request, handlerMethod.getBean()); |
46 | 48 | }
|
47 |
| - else if (handler instanceof HandlerMethod handlerMethod) { |
48 |
| - handler = handlerMethod.getBean(); |
49 |
| - return super.shouldApplyTo(request, handler); |
50 |
| - } |
51 |
| - else if (handler instanceof HandlerFunction<?> handlerFunction) { |
52 |
| - return super.shouldApplyTo(request, handlerFunction); |
53 |
| - } |
54 |
| - else if (hasGlobalExceptionHandlers() && hasHandlerMappings()) { |
| 49 | + else if (handler == null || (hasGlobalExceptionHandlers() && hasHandlerMappings())) { |
55 | 50 | return super.shouldApplyTo(request, handler);
|
56 | 51 | }
|
57 | 52 | else {
|
|
0 commit comments