zoukankan      html  css  js  c++  java
  • springboot-FilterRegistrationBean

    主要用来对servlet filter进行自定义,比如设置order。

    先写一个普通的filter:

    public class FilterDemo implements Filter {  
        private final Logger log = LoggerFactory.getLogger(FilterDemo.class);  
      
      
        @Override  
        public void destroy() {  
            log.info("" + getClass() + " destroy");  
      
        }  
      
        @Override  
        public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {  
            log.info( " doFilter " );  
            arg2.doFilter(arg0, arg1);  
      
        }  
      
        @Override  
        public void init(FilterConfig arg0) throws ServletException {  
            log.info("" + getClass() + " init");  
      
        }  
      
    }  

    配置如下:

    @Configuration  
    public class WebComponent2Config   {  
      
        @Bean  
        public FilterRegistrationBean filterDemo3Registration() {  
            FilterRegistrationBean registration = new FilterRegistrationBean();  
            registration.setFilter(filterDemo3());  
            registration.addUrlPatterns("/*");   
            registration.setName("filterDemo3");  
            registration.setOrder(6);  
            return registration;  
        }  
      
        @Bean  
        public FilterRegistrationBean filterDemo4Registration() {  
            FilterRegistrationBean registration = new FilterRegistrationBean();  
            registration.setFilter(filterDemo4());  
            registration.addUrlPatterns("/*");  
            registration.setName("filterDemo4");  
            registration.setOrder(7);  
            return registration;  
        }  
      
        @Bean  
        public Filter filterDemo3() {  
            return new FilterDemo3();  
        }  
      
        @Bean  
        public Filter filterDemo4() {  
            return new FilterDemo4();  
        }  
      
    }  
  • 相关阅读:
    需求分析与系统设计(二)阅读笔记
    阅读笔记:需求分析与系统设计(一)
    css方法div固定在网页底部
    阅读笔记:软件需求十步走(三)
    剑指offer 二维数组中的查找
    剑指offer 替换空格
    剑指offer 重建二叉树
    git常用操作
    关于 IO的同步异步间要描述
    svn-代码回滚
  • 原文地址:https://www.cnblogs.com/xiangkejin/p/8513036.html
Copyright © 2011-2022 走看看