From f5307a2eb0d53845f91f3fb80f39aa53f0d95c69 Mon Sep 17 00:00:00 2001 From: click33 <2393584716@qq.com> Date: Wed, 18 Oct 2023 02:26:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BE=9BSpringBoot3.x=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=8C=B9=E9=85=8D=E5=87=BA=E9=94=99=E7=9A=84=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sa-token-doc/more/common-questions.md | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/sa-token-doc/more/common-questions.md b/sa-token-doc/more/common-questions.md index a2028a6a..a6b3d68e 100644 --- a/sa-token-doc/more/common-questions.md +++ b/sa-token-doc/more/common-questions.md @@ -470,6 +470,60 @@ class MyConfiguration { [经验来源](https://gitee.com/dromara/sa-token/issues/I7EXIU) +### Q:SpringBoot 3.x 路由拦截鉴权报错:No more pattern data allowed after {*...} or ** pattern element + + +报错原因:SpringBoot3.x 版本默认将路由匹配机制由 `ant_path_matcher` 改为了 `path_pattern_parser` 模式, +而此模式有一个规则,就是写路由匹配符的时候,不允许 `**` 之后再出现内容。例如:`/admin/**/info` 就是不允许的。 + +如果你的项目报了这个错,说明你写的路由匹配符出现了上述问题,有三种解决方案: +1. 等待 SpringMVC 官方增强 `path_pattern_parser` 模式能力,使之可以支持 `**` 之后再出现内容。 +2. 在写路由匹配规则时,避免使 `**` 之后再出现内容。 +3. 将项目的路由匹配机制改为 `ant_path_matcher`。 + +先改项目的: +``` yml +spring: + mvc: + pathmatch: + matching-strategy: ant_path_matcher +``` + +再改 Sa-Token 的: +``` java +/** + * 自定义 SaTokenContext 实现类,重写 matchPath 方法,切换为 ant_path_matcher 模式,使之可以支持 `**` 之后再出现内容 + */ +@Primary +@Component +public class SaTokenContextByPatternsRequestCondition extends SaTokenContextForSpringInJakartaServlet { + + @Override + public boolean matchPath(String pattern, String path) { + return SaPatternsRequestConditionHolder.match(pattern, path); + } + +} +``` + + + + + + + + + + + + + + + + + + +