Spring MVC - Interceptor never called

后端 未结 6 1992
我寻月下人不归
我寻月下人不归 2021-02-15 15:06

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

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-15 15:31

    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.

提交回复
热议问题