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
If it´s possible. Use this approach:
public class Application extends WebMvcConfigurerAdapter{
...
@Bean
public MyInterceptor myInterceptor() {
return new MyInterceptor();
}
public @Override void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(myInterceptor());
}
}
instead of:
@Bean
public MappedInterceptor myInterceptor()
{
return new MappedInterceptor(null, new MyInterceptor());
}
because with the first you can use injection features (like @Autowired, etc...)