Skip to content

Change in the order between interceptors and mapped interceptors in Spring 5 #25390

@mykevinjung

Description

@mykevinjung

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
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions