详解SpringBoot解决注⼊Service为空问题⼀、⾃定义实现 HandlerInterceptor 接⼝
/**
*
* Created by zhh on 2018/04/20.
*/
public class MyInterceptor implements HandlerInterceptor {
@Autowired
private NetworkProxyInfoService networkProxyInfoService;
@Override
public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
throws Exception {
}
@Override
public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception {
// TODO Auto-generated method stub
return true;
}
}
⼆、⾃定义配置
/**
*
* Created by zhh on 2018/04/20.
*/
@Configuration
public class MyWebMvcConfig extends WebMvcConfigurerAdapter {
/**
* 将⾃定义作为Bean写⼊配置
* @return
*/
@Bean
public MyInterceptor myInterceptor() {
return new MyInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
/**
* 多个组成⼀个链
* addPathPatterns ⽤于添加拦截规则
* excludePathPatterns ⽤户排除拦截
*/
registry.addInterceptor(myInterceptor()).addPathPatterns("/**");
super.addInterceptors(registry);
}
}
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
>springboot和过滤器

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。