1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
@Configuration public class WebConfig {
@Bean public Filter tokenAuthFilter() { return new TokenAuthFilter(); } @Bean public FilterRegistrationBean tokenAuthFilterRegistration() { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(new DelegatingFilterProxy("tokenAuthFilter")); registration.addUrlPatterns("/*"); registration.setName("tokenAuthFilter"); registration.setOrder(1); return registration; }
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
public class TokenAuthFilter implements Filter {
public TokenAuthFilter() { System.out.println("myFilter"); }
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { System.out.println("filter..."); filterChain.doFilter(servletRequest, servletResponse); } }
|
springboot程序启动即可自动调用TokenAuthFilter