Spring MVC - Interceptor never called

后端 未结 6 1906
我寻月下人不归
我寻月下人不归 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:41

    I'm using Spring Boot and was having the same problem where addInterceptors() was being called to register the interceptor, but the interceptor never fired during a request. Yet XML configuration worked no problem.

    Basically, you don't need the WebMvcConfigurerAdapter class. You just need to declare an @Bean of type MappedInterceptor:

    @Bean
    public MappedInterceptor myInterceptor()
    {
        return new MappedInterceptor(null, new MyInterceptor());
    }
    

提交回复
热议问题