SpringBoot 配置过滤器
2021-01-21 08:16
标签:进入 err ram name rri component row mic except 1.配置过滤器 2.这是ssm的xml配置的过滤器 3.这是Springboot的过滤器与SSM的过滤器关系图 SpringBoot 配置过滤器 标签:进入 err ram name rri component row mic except 原文地址:https://www.cnblogs.com/Amywangqing/p/12896720.htmlpackage com.qingfeng.filter;
public class UserFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
System.out.println("进入了init方法。。。。。。" );
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("进入了doFilter方法。。。。。。" );
}
@Override
public void destroy() {
System.out.println("进入了destroy方法。。。。。。" );
}
}
package com.qingfeng.config;
importorg.springframework.boot.web.servlet.FilterRegistrationBea;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import com.qingfeng.filter.UserFilter;
@Component
public class FilterConfig {
@Bean
public FilterRegistrationBean userFilter(){
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(new UserFilter());// 设置你的过滤器或监听器对象
registrationBean.addUrlPatterns("*.do");//设置URL过滤规则,这里使用*.do的请求才能filter过滤,允许访问,没有以.do结尾的都要被拦截,不被访问
registrationBean.setName("UserFilter");//设置过滤器名字
registrationBean.addInitParameter("serverName1", " http://localhost:8080" );//给对象属性赋值
registrationBean.addInitParameter("serverName2", " http://localhost:8082" );//给对象属性赋值
registrationBean.setOrder(1);//用于设置过滤器或监听器的执行顺序
return registrationBean;
}
}
上一篇:java文件上传