在spring boot中使用@WebFilter配置filter(包括排除URL)
来源:互联网 发布:展锋股票指标源码 编辑:程序博客网 时间:2024/06/04 19:08
@WebFilter(urlPatterns = "/*")@Order(value = 1)public class TestFilter implements Filter { private static final Set<String> ALLOWED_PATHS = Collections.unmodifiableSet(new HashSet<>( Arrays.asList("/main/excludefilter", "/login", "/logout", "/register"))); @Override public void init(FilterConfig filterConfig) throws ServletException { System.out.println("init-----------filter"); } @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; String path = request.getRequestURI().substring(request.getContextPath().length()).replaceAll("[/]+$", ""); boolean allowedPath = ALLOWED_PATHS.contains(path); if (allowedPath) { System.out.println("这里是不需要处理的url进入的方法"); chain.doFilter(req, res); } else { System.out.println("这里是需要处理的url进入的方法"); } } @Override public void destroy() { System.out.println("destroy----------filter"); }}
@Order中的value越小,优先级越高。
ALLOWED_PATHS
这个是一个集合,存放的是需要排出的URL,用来判断是否是需要排除的URL。关于为什么SpringBoot中使用了@WebFilter但是过滤器却没有生效:一定要加上@Configuration注解,@Service其实也可以,其他类似。
阅读全文
0 0
- 在spring boot中使用@WebFilter配置filter(包括排除URL)
- Servlet3.0(二)--使用注解标注过滤器(Filter)@WebFilter
- spring-boot使用Filter
- Servlet3.0下@WebFilter注解配置Filter
- spring boot 配置Filter过滤器
- filter配置多个url-pattern和排除个别servlet
- spring-boot websocket 配置和实现(包括html)
- 在Servlet Filter中使用Spring容器
- 在Servlet Filter中使用Spring容器
- Spring Boot:在Spring Boot中使用Mysql和JPA
- Spring Boot:在Spring Boot中使用定时任务
- Spring Boot:在Spring Boot中使用定时任务
- Spring Boot入门一:在Eclipse中使用Spring boot
- Spring Boot使用方法小札(4):使用Serlvet中原生Filter API
- Spring Boot参考教程(六)Spring Boot配置Servlet,Filter,Listener,Interceptor
- 初识在Spring Boot中使用JPA
- 在Spring Boot中使用数据库事务
- 在Spring Boot中使用数据缓存
- VR GunJack 学习制作
- JVM系列一(基本结构)
- 文章标题
- Codeforce Round #422(Div 2) B
- 线性模型
- 在spring boot中使用@WebFilter配置filter(包括排除URL)
- 高通平台CDT解析和制作方法
- nio 非阻塞式数据传输客户端
- ORB-SLAM(五)优化
- 我的第一个hbuilder项目
- x的根号下三次方用C++怎么打
- 1. RxJava1.x的诞生(非常重要)
- java对redis的基本操作
- JAVA修改运行内存