Add interceptor to resourceHandlerMapping
The resourceHandlerMapping in the MVC Java config is not configured with any interceptors, and in particular those added through the InterceptorRegistry, which are otherwise added to all other handler mapping beans created by the config. This means that the ResourceUrlProviderExposingInterceptor (added in 4.0) is also not used for resource requests. This change ensures the ResourceUrlProviderExposingInterceptor is configured on the resourceHandlerMapping. Issue: SPR-12279
This commit is contained in:
@@ -68,6 +68,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.servlet.HandlerAdapter;
|
||||
import org.springframework.web.servlet.HandlerExceptionResolver;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.handler.AbstractHandlerMapping;
|
||||
@@ -379,9 +380,15 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
addResourceHandlers(registry);
|
||||
|
||||
AbstractHandlerMapping handlerMapping = registry.getHandlerMapping();
|
||||
handlerMapping = (handlerMapping != null ? handlerMapping : new EmptyHandlerMapping());
|
||||
handlerMapping.setPathMatcher(mvcPathMatcher());
|
||||
handlerMapping.setUrlPathHelper(mvcUrlPathHelper());
|
||||
if (handlerMapping != null) {
|
||||
handlerMapping.setPathMatcher(mvcPathMatcher());
|
||||
handlerMapping.setUrlPathHelper(mvcUrlPathHelper());
|
||||
handlerMapping.setInterceptors(new HandlerInterceptor[] {
|
||||
new ResourceUrlProviderExposingInterceptor(mvcResourceUrlProvider())});
|
||||
}
|
||||
else {
|
||||
handlerMapping = new EmptyHandlerMapping();
|
||||
}
|
||||
return handlerMapping;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user