Skip to content

Commit e5eceaf

Browse files
committed
SPR-7278 extension hook to extend the @ExceptionHandler methods for a controller
1 parent 64fd0b0 commit e5eceaf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,23 @@ private ExceptionMethodMapping getExceptionMethodMapping(HandlerMethod handlerMe
264264
ExceptionMethodMapping mapping = exceptionMethodMappingCache.get(handlerType);
265265
if (mapping == null) {
266266
Set<Method> methods = HandlerMethodSelector.selectMethods(handlerType, EXCEPTION_HANDLER_METHODS);
267+
extendExceptionHandlerMethods(methods, handlerType);
267268
mapping = new ExceptionMethodMapping(methods);
268269
exceptionMethodMappingCache.put(handlerType, mapping);
269270
}
270271
return mapping;
271272
}
272273

274+
/**
275+
* Extension hook that subclasses can override to register additional @{@link ExceptionHandler} methods
276+
* by controller type. By default only @{@link ExceptionHandler} methods from the same controller are
277+
* included.
278+
* @param methods the list of @{@link ExceptionHandler} methods detected in the controller allowing to add more
279+
* @param handlerType the controller type to which the @{@link ExceptionHandler} methods will apply
280+
*/
281+
protected void extendExceptionHandlerMethods(Set<Method> methods, Class<?> handlerType) {
282+
}
283+
273284
/**
274285
* MethodFilter that matches {@link ExceptionHandler @ExceptionHandler} methods.
275286
*/

0 commit comments

Comments
 (0)