@Configuration public class InterceptorConfig implements WebMvcConfigurer { /** * 若要在Interceptor中进行依赖注入,则需要: * 将拦截器注册为一个 Bean * @return */ @Bean public PermissionInterceptor permissionInterceptor() { return new PermissionInterceptor(); } @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(permissionInterceptor()) .addPathPatterns("/**") //默认过滤全部 .excludePathPatterns("/swagger-resources/**") //需要排除的地址 .excludePathPatterns("/v2/api-docs/**"); WebMvcConfigurer.super.addInterceptors(registry); } }
public class PermissionInterceptor implements HandlerInterceptor { @Autowired LogRepository logRepository; //在Configuration中配置Bean后,该@Autowired才会生效 @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {}
posted on
浙公网安备 33010602011771号