OncePerRequestFilter过滤swagger
时间: 2023-11-11 08:58:19 浏览: 201
Filter过滤
4星 · 用户满意度95%
您可以通过在OncePerRequestFilter中判断请求的URL是否包含Swagger UI的路径来过滤掉与Swagger UI相关的请求。
以下是代码示例:
```java
public class SwaggerFilter extends OncePerRequestFilter {
private static final String SWAGGER_UI_PATH = "/swagger-ui.html";
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
String path = request.getRequestURI();
if (!StringUtils.contains(path, SWAGGER_UI_PATH)) {
filterChain.doFilter(request, response);
}
}
}
```
阅读全文