欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解SpringBoot 解決攔截器注入Service為空問題

 更新時(shí)間:2018年06月28日 13:45:10   作者:DavidHH  
這篇文章主要介紹了詳解SpringBoot 解決攔截器注入Service為空問題的解決,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧

一、自定義攔截器實(shí)現(xiàn) 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 {
  networkProxyInfoService.getAllNetworkProxyInfoByIsValid(GobalConstant.ProxyValid.VALID);
 }

 @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) {
  /**
   * 多個(gè)攔截器組成一個(gè)攔截器鏈
   * addPathPatterns 用于添加攔截規(guī)則
   * excludePathPatterns 用戶排除攔截
   */
  registry.addInterceptor(myInterceptor()).addPathPatterns("/**");
  super.addInterceptors(registry);
 } 
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論