spring boot filter -Autowired

Posted FeeCy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot filter -Autowired相关的知识,希望对你有一定的参考价值。

需求:在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

以上是关于spring boot filter -Autowired的主要内容,如果未能解决你的问题,请参考以下文章

spring boot filter -Autowired

spring boot filter实现

Spring boot servlet,filter,Listener,Interceptor

Spring boot servlet,filter,Listener,Interceptor

Spring boot servlet,filter,Listener,Interceptor

Spring Boot 之FilterRegistrationBean --支持web Filter 排序的使用(转)