springboot整合过滤器

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_36331657/article/details/88080234

1、编写一个普通的Filter

public class HeFilter implements Filter {
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
	}
	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		System.out.println("he您已进入filter过滤器,您的请求正常,请继续遵规则...");
		chain.doFilter(request, response);
	}
	@Override
	public void destroy() {
	}
}

2、编写一个Springboot的配置类;

@Configuration
public class ServletConfig {
    
    @Bean
    public FilterRegistrationBean heFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean(new HeFilter());
        registration.addUrlPatterns("/*");
        return registration;
    }
}
展开阅读全文

没有更多推荐了,返回首页