I stumbled upon a configuration class for a project that was converted from legacy spring to Spring Boot. I see there are two ways interceptors are added. Like these
@Configuration
public class AppConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor( new MyInterceptorOne()).addPathPatterns("/api/data/**");
}
@Bean
public MappedInterceptor mappedResponseHeaderInterceptor() {
return new MappedInterceptor(new String[] { "/static/css/**", "/static/img/**" }, new ResponseHeaderInterceptor());
}
}
both interceptors are working. I am wondering what is right way to add the interceptors in Spring boot and why these two method exists