国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

java - SpringBoot adds a custom interceptor but does not call it
PHP中文網(wǎng)
PHP中文網(wǎng) 2017-06-30 09:54:03
0
4
1147

1. Question:

要添加一個自定義處理Token的問題,現(xiàn)在實現(xiàn)了方法,卻發(fā)現(xiàn)攔截器沒有被調(diào)用。
我是在自定義的HandlerInterceptorAdapter里面重寫了preHandle方法。并把這個自定義的HandlerInterceptorAdapter添加到了自定義的WebMvcConfigurerAdapter,在WebMvcConfigurerAdapter添加@Configuration注解,但是卻沒有被調(diào)用!

2. Code:
AccessTokenVerifyInterceptor of custom HandlerInterceptorAdapter:

@Component
public class AccessTokenVerifyInterceptor extends HandlerInterceptorAdapter {
    
    private Logger logger = LoggerFactory.getLogger(AccessTokenVerifyInterceptor.class);
    
    @Autowired
    private FFAccessTokenService tokenService;
    
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        // TODO Auto-generated method stub
        
        logger.info("AccessToken executing ...");
        return true;    
    }
    
}

Customized WebMvcConfigurerAdapter class FFWebMvcConfigurer:

@Configuration
public class FFWebMvcConfigurer extends WebMvcConfigurerAdapter {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // TODO Auto-generated method stub
        registry.addViewController("/error").setViewName("404.html");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE); 
        super.addViewControllers(registry);    
    }
        
     @Override 
     public void configurePathMatch(PathMatchConfigurer configurer) { 
         configurer.setUseSuffixPatternMatch(false); 
         super.configurePathMatch(configurer); 
     }
     
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
         
         registry.addInterceptor(new AccessTokenVerifyInterceptor())
                  .addPathPatterns("/**")
                  .excludePathPatterns("/access-token");
         
         super.addInterceptors(registry);
         
         System.out.println("開始開始咯。。。。");    
    } 
}

3. I hope that all the masters can give me some advice, thank you!

PHP中文網(wǎng)
PHP中文網(wǎng)

認證高級PHP講師

reply all(4)
Peter_Zhu

/**Remove one* and try it

扔個三星炸死你

Add
@ServletComponentScan

to the startup class
阿神

Then you should post the HandlerInterceptorAdapter and take a look
Also, the @Component annotation in 2 is meaningless.

學(xué)霸

No, I wrote a simple demo based on your code, and the interceptor can be called.

@Configuration
public class FFWebMvcConfigurer extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/error").setViewName("404.html");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        super.addViewControllers(registry);
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setUseSuffixPatternMatch(false);
        super.configurePathMatch(configurer);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new AccessTokenVerifyInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/access-token");

        super.addInterceptors(registry);

        System.out.println("開始開始咯。。。。");
    }

}
public class AccessTokenVerifyInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle...");
        return true;
    }

}

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template