Skip to content

Duplicate calls of a custom HandlerInterceptor's methods after updating to Spring Data REST 3.4 #1955

@lwitzani

Description

@lwitzani

Hi,
Background:
We have a Spring Boot project and recently updated our dependencies from Spring Boot 2.3.7.RELEASE to 2.4.0!
Spring Framework therefore changed from 5.2.12.RELEASE to 5.3.1

Use case:
We have a custom interceptor (let's call it ActivityLoggerInterceptor) that implements org.springframework.web.servlet.HandlerInterceptor
We are registering the interceptor similar to the following:

@Configuration
public class WebMvcConfig {

    @Bean
    public MappedInterceptor mappedInterceptor() {
        return new MappedInterceptor(
                new String[]{"/api/**"},
                new ActivityLoggerInterceptor()
        );
    }
}

This worked perfectly on Spring Boot 2.3.7.RELEASE / Spring 5.2.12.RELEASE meaning the handler methods preHandle and afterCompletion were called once per request.

The issue:
After updating to Spring Boot 2.4.0 / Spring 5.3.1 the methods preHandle and afterCompletion in our interceptor are each called twice

Observations:
After some debugging i found that our Interceptor is somehow now found twice (see the picture below).
duplicateInterceptorCalls

From there it goes deep into Spring ...
Because of this and because i did not find anything that our registration of the Interceptor could be wrong now, i am writing this issue.
Looking through the closed and open issues i did not find anything that would match this problem. But it seems that something around MappedInterceptors has changed in Spring.

Can you help me somehow :)? Thanks so much!

Best regards,
Lukas

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions