diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurer.java index b1bf08e2203..85c09d382b1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurer.java @@ -134,6 +134,13 @@ public interface WebMvcConfigurer { * Add Spring MVC lifecycle interceptors for pre- and post-processing of * controller method invocations. Interceptors can be registered to apply * to all requests or be limited to a subset of URL patterns. + *

Note that interceptors registered here only apply to + * controllers and not to resource handler requests. To intercept requests for + * static resources either declare a + * {@link org.springframework.web.servlet.handler.MappedInterceptor MappedInterceptor} + * bean or switch to advanced configuration mode by extending + * {@link org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport + * WebMvcConfigurationSupport} and then override {@code resourceHandlerMapping}. */ void addInterceptors(InterceptorRegistry registry); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java index 16e1d379a22..88b1b86d9f2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java @@ -21,8 +21,16 @@ import org.springframework.web.context.request.WebRequestInterceptor; import org.springframework.web.servlet.HandlerInterceptor; /** - * Holds information about a HandlerInterceptor mapped to a path into the application. - * Provides a method to match a request path to the mapped path patterns. + * Contains a {@link HandlerInterceptor} along with include (and optionally + * exclude) path patterns to which the interceptor should apply. Also provides + * matching logic to test if the interceptor applies to a given request path. + * + *

A MappedInterceptor can be registered directly with any + * {@link org.springframework.web.servlet.handler.AbstractHandlerMethodMapping + * AbstractHandlerMethodMapping}. Furthermore, beans of type MappedInterceptor + * are automatically detected by {@code AbstractHandlerMethodMapping} (including + * ancestor ApplicationContext's) which effectively means the interceptor is + * registered "globally" with all handler mappings. * * @author Keith Donald * @author Rossen Stoyanchev diff --git a/spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc-4.1.xsd b/spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc-4.1.xsd index 037d85f9c8a..c3ef3b7f021 100644 --- a/spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc-4.1.xsd +++ b/spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc-4.1.xsd @@ -563,7 +563,7 @@ Interceptors allow requests to be pre/post processed before/after handling. Each inteceptor must implement the org.springframework.web.servlet.HandlerInterceptor or org.springframework.web.context.request.WebRequestInterceptor interface. - The interceptors in this set are automatically configured on each registered HandlerMapping. + The interceptors in this set are automatically detected by every registered HandlerMapping. The URI paths each interceptor applies to are configurable. ]]>