servlet过滤器会抑制许多swagger响应(包括图像和css),以便在浏览器上创建swagger ul gui屏幕。请通过以下代码段绕过此类行为。
@Component
public class DomainAuthorizationFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
if(httpRequest.getRequestURI().trim().toLowerCase().matches(".*swagger-.*|.*api-docs.*"))
{ request.getRequestDispatcher(httpRequest.getServletPath()).forward(request, response);
return;
}
else {
// Your login in the filter.
}
chain.doFilter(request, response);
}
}
1条答案
按热度按时间vsdwdz231#
我们需要添加上述过滤器,在我们的spring引导控制器中,我们需要-