package com.hzya.frame.webapp.web.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Content注册过滤器，设置过滤器优先级以及过滤路径
 * @Author 👻👻👻👻👻👻👻👻👻👻 gjh
 * @Date 2022-12-06 10:34
 * @Version 1.0
 */
@Configuration
public class FilterConfiguration {
    @Bean
    public FilterRegistrationBean<ExceptionOptionFilter> ExceptionOptionFilter() {
        //通过FilterRegistrationBean实例设置优先级可以生效
        //通过@WebFilter无效
        FilterRegistrationBean<ExceptionOptionFilter> bean = new FilterRegistrationBean<ExceptionOptionFilter>();
        bean.setFilter(new ExceptionOptionFilter());//注册自定义过滤器
        bean.setName("fxceptionOptionFilter");//过滤器名称
        bean.addUrlPatterns("/*");//过滤所有路径
        bean.setOrder(1);//优先级，最顶级
        return bean;
    }

    @Bean
    public FilterRegistrationBean<BaseFilter> BaseFilter() {
        //通过FilterRegistrationBean实例设置优先级可以生效
        //通过@WebFilter无效
        FilterRegistrationBean<BaseFilter> bean = new FilterRegistrationBean<BaseFilter>();
        bean.setFilter(new BaseFilter());//注册自定义过滤器
        bean.setName("baseFilter");//过滤器名称
        bean.addUrlPatterns("/*");//过滤所有路径
        bean.setOrder(2);//优先级，越低越优先
        return bean;
    }

}
