-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
When a handler mapping creates a HandlerExecutionChain, Spring 4.1.x added adaptedInterceptors first and then added mappedInterceptors as shown here.
However, Spring 5.1.x merged adapted interceptors and mapped interceptors into adaptedInterceptors variable and getHandlerExecutionChain returns whatever in the order in adaptedInterceptors variable as shown here. However, when the handler mapping populates adaptedInterceptors, it adds mapped interceptors into adaptedInterceptors first and then adds regular interceptors into adaptedInterceptors later as shown here.
As a result, mapped interceptors are executed first and then regular interceptors are executed later in Spring 5 while regular interceptors were executed first and then mapped interceptors were executed later in Spring 4. Is this an intended change? I noticed this while I am upgrading Spring version from 4.1.x to 5.1.x in my application. How can I override in Spring 5 so that regular interceptors are executed first and then mapped interceptors executed after?
Maybe AbstractHandlerMapping.initApplicationContext should be as following?
@Override
protected void initApplicationContext() throws BeansException {
extendInterceptors(this.interceptors);
initInterceptors(); // init and adapt this.interceptors first
detectMappedInterceptors(this.adaptedInterceptors); // then adapt mapped interceptors
}