How can you configure a Spring MVC interceptor to apply globally?

Applying an interceptor globally means registering it so it runs for every incoming request across the entire application, rather than being tied to a single controller. In Spring MVC this is done through a central configuration class rather than an annotation on the interceptor itself.

Key Points

Example

A logging interceptor registered with no path pattern restrictions runs on every request in the application, while an authentication interceptor might be scoped with addPathPatterns("/admin/**") to apply only to admin routes.

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoggingInterceptor());
        registry.addInterceptor(new AuthInterceptor())
                .addPathPatterns("/admin/**");
    }
}

Interview Tip

A concise interview answer is

I register global interceptors in a @Configuration class that implements WebMvcConfigurer, overriding addInterceptors to call registry.addInterceptor. Leaving out addPathPatterns applies the interceptor to every request, while specifying it scopes the interceptor to just the routes that need it.

Last updated: 11 November 2026

Previous question: What are the methods in the HandlerInterceptor interface?

Next question: What is the difference between a Spring MVC interceptor and a web filter?

More Spring MVC (Optional) interview questions

All Spring MVC (Optional) questions