Skip to content

Commit fbfa67e

Browse files
author
Keith Donald
committed
ordered sorting
1 parent f6a2e58 commit fbfa67e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
import javax.servlet.http.HttpServletRequest;
2525

2626
import org.springframework.beans.BeansException;
27+
import org.springframework.beans.factory.BeanFactoryUtils;
28+
import org.springframework.core.OrderComparator;
2729
import org.springframework.core.Ordered;
2830
import org.springframework.web.context.request.WebRequestInterceptor;
2931
import org.springframework.web.context.support.WebApplicationObjectSupport;
3032
import org.springframework.web.servlet.HandlerExecutionChain;
3133
import org.springframework.web.servlet.HandlerInterceptor;
3234
import org.springframework.web.servlet.HandlerMapping;
35+
import org.springframework.web.servlet.ViewResolver;
3336

3437
/**
3538
* Abstract base class for {@link org.springframework.web.servlet.HandlerMapping}
@@ -142,19 +145,20 @@ protected void extendInterceptors(List interceptors) {
142145
*/
143146
protected void initInterceptors() {
144147
if (this.detectInterceptors) {
145-
Map<String, HandlerInterceptor> handlerInterceptors = getApplicationContext().getBeansOfType(HandlerInterceptor.class);
146-
if (handlerInterceptors != null && !handlerInterceptors.isEmpty()) {
148+
Map<String, HandlerInterceptor> handlerInterceptors = BeanFactoryUtils.beansOfTypeIncludingAncestors(getApplicationContext(), HandlerInterceptor.class, true, false);
149+
if (!handlerInterceptors.isEmpty()) {
147150
this.interceptors.addAll(handlerInterceptors.values());
148151
}
149-
Map<String, WebRequestInterceptor> webInterceptors = getApplicationContext().getBeansOfType(WebRequestInterceptor.class);
150-
if (webInterceptors != null && !webInterceptors.isEmpty()) {
152+
Map<String, WebRequestInterceptor> webInterceptors = BeanFactoryUtils.beansOfTypeIncludingAncestors(getApplicationContext(), WebRequestInterceptor.class, true, false);
153+
if (!webInterceptors.isEmpty()) {
151154
for (WebRequestInterceptor interceptor : webInterceptors.values()) {
152155
this.interceptors.add(new WebRequestHandlerInterceptorAdapter(interceptor));
153156
}
154157
}
155158
}
156159

157160
if (!this.interceptors.isEmpty()) {
161+
OrderComparator.sort(this.interceptors);
158162
this.adaptedInterceptors = new HandlerInterceptor[this.interceptors.size()];
159163
for (int i = 0; i < this.interceptors.size(); i++) {
160164
Object interceptor = this.interceptors.get(i);

0 commit comments

Comments
 (0)