use of org.springframework.messaging.handler.annotation.MessageExceptionHandler in project spring-framework by spring-projects.
the class AnnotationExceptionHandlerMethodResolver method initExceptionMappings.
private static Map<Class<? extends Throwable>, Method> initExceptionMappings(Class<?> handlerType) {
Map<Method, MessageExceptionHandler> methods = MethodIntrospector.selectMethods(handlerType, new MethodIntrospector.MetadataLookup<MessageExceptionHandler>() {
@Override
public MessageExceptionHandler inspect(Method method) {
return AnnotationUtils.findAnnotation(method, MessageExceptionHandler.class);
}
});
Map<Class<? extends Throwable>, Method> result = new HashMap<>();
for (Map.Entry<Method, MessageExceptionHandler> entry : methods.entrySet()) {
Method method = entry.getKey();
List<Class<? extends Throwable>> exceptionTypes = new ArrayList<>();
exceptionTypes.addAll(Arrays.asList(entry.getValue().value()));
if (exceptionTypes.isEmpty()) {
exceptionTypes.addAll(getExceptionsFromMethodSignature(method));
}
for (Class<? extends Throwable> exceptionType : exceptionTypes) {
Method oldMethod = result.put(exceptionType, method);
if (oldMethod != null && !oldMethod.equals(method)) {
throw new IllegalStateException("Ambiguous @ExceptionHandler method mapped for [" + exceptionType + "]: {" + oldMethod + ", " + method + "}");
}
}
}
return result;
}
Aggregations