发布于 4年前

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

©2020 edoou.com   京ICP备16001874号-3