diff --git a/sa-token-demo/sa-token-demo-webflux/src/main/java/com/pj/satoken/SaTokenConfigure.java b/sa-token-demo/sa-token-demo-webflux/src/main/java/com/pj/satoken/SaTokenConfigure.java index 287f9401..6fb386a0 100644 --- a/sa-token-demo/sa-token-demo-webflux/src/main/java/com/pj/satoken/SaTokenConfigure.java +++ b/sa-token-demo/sa-token-demo-webflux/src/main/java/com/pj/satoken/SaTokenConfigure.java @@ -1,12 +1,10 @@ package com.pj.satoken; +import cn.dev33.satoken.reactor.filter.SaReactorFilter; +import com.pj.util.AjaxJson; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.pj.util.AjaxJson; - -import cn.dev33.satoken.reactor.filter.SaReactorFilter; - /** * [Sa-Token 权限认证] 配置类 * @author click33 @@ -33,6 +31,7 @@ public class SaTokenConfigure { // 指定[异常处理函数]:每次[认证函数]发生异常时执行此函数 .setError(e -> { System.out.println("---------- sa全局异常 "); + e.printStackTrace(); return AjaxJson.getError(e.getMessage()); }) ; diff --git a/sa-token-doc/more/common-questions.md b/sa-token-doc/more/common-questions.md index 0b87c7f2..04f7c4cf 100644 --- a/sa-token-doc/more/common-questions.md +++ b/sa-token-doc/more/common-questions.md @@ -534,7 +534,35 @@ public class SaTokenContextByPatternsRequestCondition extends SaTokenContextForS ``` +### Q:Webflux 环境集成,或者 SpringCloud Gateway 环境集成后,过滤器里路由拦截鉴权报错:`java.lang.NoSuchFieldError: defaultInstance` +``` java +java.lang.NoSuchFieldError: defaultInstance + at cn.dev33.satoken.spring.pathmatch.SaPathPatternParserUtil.match(SaPathPatternParserUtil.java:40) + at cn.dev33.satoken.reactor.spring.SaTokenContextForSpringReactor.matchPath(SaTokenContextForSpringReactor.java:34) + at cn.dev33.satoken.router.SaRouter.isMatch(SaRouter.java:58) + at cn.dev33.satoken.router.SaRouter.isMatch(SaRouter.java:72) + ... +``` + +原因:SpringBoot 版本用的太低了,导致一些类不存在。 + +- 方案一:升级项目的 SpringBoot 版本至 `2.3.x` 以上 +- 方案二:像上面的问题解决方案一样,重写一下相关类: + +``` java +/** + * 自定义 SaTokenContext 实现类,重写 matchPath 方法,将 PathPatternParser.defaultInstance 改为 SaPathMatcherHolder.getPathMatcher() + */ +@Primary +@Component +public class SaTokenContextByPatternsRequestCondition extends SaTokenContextForSpringReactor { + @Override + public boolean matchPath(String pattern, String path) { + return SaPathMatcherHolder.getPathMatcher().match(pattern, path); + } +} +```