@Component
public class WebFilterTest implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.out.println("拦截器生效");
return false;
}
}
@SpringBootConfiguration
public class HandleConfig implements WebMvcConfigurer {
private WebFilterTest webFilter;
@Autowired
public HandleConfig(WebFilterTest webFilter) {
this.webFilter = webFilter;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(webFilter);
}
}