I am trying to configure an interceptor in my application and I am not being able to make it work.
In my application configuration class, I have configured in the follow
Can someone please mark Theos answer as the correct one? I had the situation of a perfectly working Spring Boot app using i18n and Thymeleaf (with a layout interceptor) as long as the app was running localhost with the following config:
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
registry.addInterceptor(thymeleafLayoutInterceptor());
}
As soon as I deployed the app to an Elasticbeanstalk instance, both interceptors were not fired anymore. Although added once. When I changed the setting to
@Bean
public MappedInterceptor localeInterceptor() {
return new MappedInterceptor(null, localeChangeInterceptor());
}
@Bean
public MappedInterceptor thymeleafInterceptor() {
return new MappedInterceptor(null, thymeleafLayoutInterceptor());
}
everything was working fine on all environments. There must be an issue with firing interceptors added with addInterceptor, it might depend on the URL that is used to invoke the request - I don't know.
Thanks for your answer, Theo, I just wanted to add this here if some else stumbles upon this nice feature.