A {@link org.springframework.web.servlet.View} object.
*
A {@link java.lang.String} value which is interpreted as view name.
+ *
{@link ResponseBody @ResponseBody} annotated methods (Servlet-only)
+ * to set the response content. The return value will be converted to the
+ * response stream using
+ * {@linkplain org.springframework.http.converter.HttpMessageConverter message converters}.
+ *
An {@link org.springframework.http.HttpEntity HttpEntity<?>} or
+ * {@link org.springframework.http.ResponseEntity ResponseEntity<?>} object
+ * (Servlet-only) to set response headers and content. The ResponseEntity body
+ * will be converted and written to the response stream using
+ * {@linkplain org.springframework.http.converter.HttpMessageConverter message converters}.
*
void if the method handles the response itself (by
* writing the response content directly, declaring an argument of type
* {@link javax.servlet.ServletResponse} / {@link javax.servlet.http.HttpServletResponse}
diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionResolver.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionResolver.java
new file mode 100644
index 0000000000..e0c07c2a6d
--- /dev/null
+++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionResolver.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.web.bind.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+/**
+ * An {@linkplain Component @Component} annotation that indicates the annotated class
+ * contains {@linkplain ExceptionHandler @ExceptionHandler} methods. Such methods
+ * will be used in addition to {@code @ExceptionHandler} methods in
+ * {@code @Controller}-annotated classes.
+ *
+ *
In order for the the annotation to detected, an instance of
+ * {@code org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver}
+ * is configured.
+ *
+ *
Classes with this annotation may use the {@linkplain Order @Order} annotation
+ * or implement the {@link Ordered} interface to indicate the order in which they
+ * should be used relative to other such annotated components. However, note that
+ * the order is only for components registered through {@code @ExceptionResolver},
+ * i.e. within an
+ * {@code org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver}.
+ *
+ * @author Rossen Stoyanchev
+ * @since 3.2
+ *
+ * @see org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Component
+public @interface ExceptionResolver {
+
+}
\ No newline at end of file
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java
index c105ba1d82..9f4a90f090 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java
@@ -18,15 +18,23 @@ package org.springframework.web.servlet.mvc.method.annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Source;
+import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.core.annotation.AnnotationAwareOrderComparator;
+import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
@@ -34,6 +42,7 @@ import org.springframework.http.converter.xml.SourceHttpMessageConverter;
import org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter;
import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ExceptionResolver;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.method.annotation.ExceptionHandlerMethodResolver;
@@ -49,6 +58,8 @@ import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver;
+import edu.emory.mathcs.backport.java.util.Collections;
+
/**
* An {@link AbstractHandlerMethodExceptionResolver} that resolves exceptions
* through {@code @ExceptionHandler} methods.
@@ -62,7 +73,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionRes
* @since 3.1
*/
public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExceptionResolver implements
- InitializingBean {
+ InitializingBean, ApplicationContextAware {
private List customArgumentResolvers;
@@ -72,13 +83,18 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce
private ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager();
- private final Map, ExceptionHandlerMethodResolver> exceptionHandlerMethodResolvers =
- new ConcurrentHashMap, ExceptionHandlerMethodResolver>();
+ private final Map, ExceptionHandlerMethodResolver> exceptionHandlersByType =
+ new ConcurrentHashMap, ExceptionHandlerMethodResolver>();
+
+ private final Map