Register Spring HandlerInterceptor Without WebMvcConfigurationSupport

前端 未结 2 2011
清酒与你
清酒与你 2021-01-11 20:15

I\'m trying to register an instance of HandlerInterceptor in Spring using Java Config without extending WebMvcConfigurationSupport. I\'m c

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-11 21:14

    Edit: This class has since been deprecated. See @bosco answer below for the Spring 5 equivalent.

    Figured it out, the solution is to use, simply:

    @Configuration
    public class AnnotationSecurityConfiguration extends WebMvcConfigurerAdapter {
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new SecurityAnnotationHandlerInterceptor());
        }
    
    }
    

    In spring boot, all beans of type WebMvcConfigurer are automatically detected and can modify the MVC context.

提交回复
热议问题