为什么我的拦截器没办法生效
自定义拦截器
@Component
public class IpCountInteceptor implements HandlerInterceptor {
@Autowired
private IpCounterService ipCounterService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
ipCounterService.record();
return true;
}
}
注册拦截器
@Configuration
@ComponentScan(basePackages = {"com.han.inteceptor"})
public class WebConfig implements WebMvcConfigurer {
@Autowired
private IpCountInteceptor ipCountInteceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(ipCountInteceptor);
}
}