mirror of
https://gitee.com/dromara/sa-token.git
synced 2024-11-29 18:37:49 +08:00
优化文档和demo示例
This commit is contained in:
parent
7f5ae11961
commit
b92ba4de87
@ -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());
|
||||
})
|
||||
;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user