Spring HandlerInterceptor mapping with annotations

前端 未结 2 1398
旧巷少年郎
旧巷少年郎 2021-02-14 22:00

Good day. I got a spring mvc application and 2 controllers inside. First controller (PublicController) can process requests from all users, Second (PrivateController) can only

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-14 22:23

    Just solve it.

    @Configuration
    @EnableWebMvc
    @ComponentScan(basePackages="webapp.base.package")
    public class WebApplicationConfig extends WebMvcConfigurerAdapter {
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new LoggerInterceptor()).addPathPatterns("/**");;
            registry.addInterceptor(new AccessInterceptor()).addPathPatterns("/private/**");;
        }
    
    }
    

提交回复
热议问题