CR Sardar
CR Sardar

Reputation: 1018

Spring WebMVC 5 - Annotation based Interceptor

How to configure an Interceptor, through Annotation only(I do NOT like to register the interceptor in .XML file, I do not use .XML based configuration)?

Note : I see in example on internet it is suggesting to use org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter, when I tried to use it, I found it is DEPRECATED

I am testing on SpringWebMVC-5 with SpringBoot-2

Upvotes: 0

Views: 361

Answers (1)

Andrew Lapham
Andrew Lapham

Reputation: 478

In Spring5 you can use org.springframework.web.servlet.config.annotation.WebMvcConfigurer:

@EnableWebMvc
@Configuration
public class WebConfig implements WebMvcConfigurer {

     @Override
     public void addInterceptors(InterceptorRegistry registry) {
          registry.addInterceptor(....);
     }
 }

Upvotes: 1

Related Questions