HandlerInterceptor注入bean报错
报错的配置
@Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new DemoInterceptor());
}
}
ok的配置
@Component
public class DemoInterceptor implements HandlerInterceptor {
}
@Configuration
public class InterceptorCongif extends WebMvcConfigurerAdapter {
@Autowired
DemoInterceptor demoInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(demoInterceptor);
}
}
doc