您的位置:首页 > 编程语言 > Java开发

已经解决 spring boot 拦截器中注入bean

2017-04-03 22:20 567 查看
已经解决 spring boot 拦截器中如何注入bean的问题

@Configuration
public class MyWebAppConfigurer extends WebMvcConfigurerAdapter


@Bean
RequestInterceptor requestInterceptor() {
return new RequestInterceptor();
}


@Component
public class RequestInterceptor implements HandlerInterceptor


@Autowired
private ApplicationConfiguration configuration;


// 多个拦截器组成一个拦截器链
// addPathPatterns 用于添加拦截规则
// excludePathPatterns 用户排除拦截
@Override
public void addInterceptors(InterceptorRegistry registry) {

//时间拦截器
registry.addInterceptor(requestExecuteTimeInterceptor()).addPathPatterns("/**");

//API请求拦截器
registry.addInterceptor(requestInterceptor()).addPathPatterns("/**").excludePathPatterns("/weixin/server");

super.addInterceptors(registry);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring boot