需求:在SpringBoot实现拦截器,并且需要自定义的filter类型自动装配一些对象

自定义的过滤器类

public class SessionExpireFilter implements Filter{
    @Autowired
    private StringRedisTemplate redisTemplate; 
 }

 

重点是变量自动配置类

@Configuration
public class MyFilter  {
    @Bean
    public FilterRegistrationBean sessionExpireFilter(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(this.SessionExpireFilter());
        registrationBean.addUrlPatterns("/*");
        return registrationBean;
    }

    @Bean
    public Filter SessionExpireFilter() {
        return new SessionExpireFilter();
    }
}

原文:https://blog.csdn.net/ycd500756/article/details/81676456

posted on 2019-01-15 14:50  FeeCy  阅读(856)  评论(0编辑  收藏  举报