diff --git a/continew-starter-core/src/main/java/top/continew/starter/core/util/SpringWebUtils.java b/continew-starter-core/src/main/java/top/continew/starter/core/util/SpringWebUtils.java index 031d54a9..9743a0a6 100644 --- a/continew-starter-core/src/main/java/top/continew/starter/core/util/SpringWebUtils.java +++ b/continew-starter-core/src/main/java/top/continew/starter/core/util/SpringWebUtils.java @@ -23,6 +23,7 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.http.HttpServletRequest; import org.springframework.context.ApplicationContext; import org.springframework.http.server.PathContainer; +import org.springframework.util.AntPathMatcher; import org.springframework.web.accept.ContentNegotiationManager; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerExecutionChain; @@ -50,6 +51,8 @@ public class SpringWebUtils { private SpringWebUtils() { } + private static final AntPathMatcher matcher = new AntPathMatcher(); + /** * 路径是否匹配 * @@ -88,6 +91,30 @@ public class SpringWebUtils { return pathPattern.matches(pathContainer); } + /** + * 路径是否匹配 - Ant 风格 + * + * @param path 路径 + * @param pattern 匹配模式 + * @return 是否匹配 + * @since 2.4.0 + */ + public static boolean isMatchAnt(String path, String pattern) { + return matcher.match(pattern, path); + } + + /** + * 路径是否匹配 - Ant 风格 + * + * @param path 路径 + * @param patterns 匹配模式列表 + * @return 是否匹配 + * @since 2.6.0 + */ + public static boolean isMatchAnt(String path, List patterns) { + return patterns.stream().anyMatch(pattern -> isMatchAnt(path, pattern)); + } + /** * 取消注册静态资源映射 * diff --git a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/util/AccessLogUtils.java b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/util/AccessLogUtils.java index 9db8f446..8fb221ed 100644 --- a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/util/AccessLogUtils.java +++ b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/util/AccessLogUtils.java @@ -40,10 +40,10 @@ public class AccessLogUtils { } /** - * 资源路径 - doc 路径 + * 静态资源路径模式 */ private static final List RESOURCE_PATH = List - .of("/doc/**", "/v2/api-docs/**", "/v3/api-docs/**", "/webjars/**", "/swagger-resources/**", "/swagger-ui.html"); + .of("/**/doc/**", "/**/doc.html", "/**/nextdoc/**", "/**/v*/api-docs/**", "/**/api-docs/**", "/**/swagger-ui/**", "/**/swagger-ui.html", "/**/swagger-resources/**", "/**/webjars/**", "/**/favicon.ico", "/**/static/**", "/**/assets/**", "/**/actuator/**", "/error", "/health"); /** * 获取参数信息 @@ -91,7 +91,7 @@ public class AccessLogUtils { public static boolean exclusionPath(LogProperties properties, String path) { // 放行路由配置的排除检查 return properties.isMatch(path) || RESOURCE_PATH.stream() - .anyMatch(resourcePath -> SpringWebUtils.isMatch(path, resourcePath)); + .anyMatch(resourcePath -> SpringWebUtils.isMatchAnt(path, resourcePath)); } /**