Comments (3)
今天打断点找了下问题,问题就出在响应式中flatMap切换了线程,boxThreadLocal不是原来的线程上下文了,所以拿不到原线程的上下文内容导致报错,webflux的确是切换线程的,所以应该依赖于contextWrite存储和deferContextual去取才对。
在本地不会报错就是本地测试不会切换线程,只有上服务器才会
public static Box getBoxNotNull() {
Box box = boxThreadLocal.get();
if(box == null) {
throw new InvalidContextException("未能获取有效的上下文").setCode(SaErrorCode.CODE_10002);
}
return box;
};
from sa-token.
@zhuangzibin 你解决这个问题了么?通过 deferContextual 或者 contextWrite 这个需要在 response 里才能获取到吧
应该要修改 ServerRequest.bodyToMono 的实现?
from sa-token.
@zhuangzibin 你解决这个问题了么?通过 deferContextual 或者 contextWrite 这个需要在 response 里才能获取到吧
应该要修改 ServerRequest.bodyToMono 的实现?
其实官方的demo有写,在调用他的工具类时,先set一次,在另一个线程初始化上下文。如果你不使用他的工具类,可以考虑在拦截器那里就把用户信息放到Mono的上下文里,然后自己写工具类去上下文取,就不依赖于他的stpUtil工具类
return SaReactorHolder.getContextAndSetSync()
.map(ignore -> {
StpUtil.login(1L, new SaLoginModel()
.setDevice("APP")
.setExtra(UserUtil.USER_ID, 1L));
return 1L;
});
from sa-token.
Related Issues (20)
- 在GateWay中使用SaReactorFilter,跨域配置失效 HOT 1
- 关于文档内SSO实现refreshToken的安全性问题 HOT 2
- 关于微服务下Satoken和SameToken的验证疑问? HOT 2
- 鉴权能否支持动态获取入参,并将入参作为角色code或者权限code的前缀? HOT 4
- 使用jackson 2.17.0报错 HOT 1
- 并发并且多SaSignConfig配置的情况下签名失败 HOT 1
- 多账号认证 OAuth2中 setSaOAuth2Config 中使用自定义StpUserUtil登录失效
- token过期抛出的异常问题
- Spring Cloud Gateway 2022已经使用reactor-core 3.x,WebFlux框架高度依赖Reactor,**建议保持和 Gateway Reactor版本同步** HOT 2
- 会话查询功能结果顺序每次返回都不同
- Stateless模式的JWT使用方式 logout没有事件推送吗?
- 未能获取有效的上下文 HOT 1
- StpUtil.getTokenInfo()的isLogin在退出后显示不正确
- JDK17之后 javax 的依赖名称全部改为 jakarta HOT 1
- jwt模式无效token没有抛出token无效的异常
- API接口验签 bug HOT 2
- 在非 web 场景中使用 SaStorage 不得不处理 SaTokenContext 这极其不合理 Storage 不应与Request和Response 捆绑
- sa-token1.38.0的插件不支持dubbo3.1版本
- 自动刷新续签
- Spring cloud Gateway中,配置全局过滤器,但是断点之后不走全局过滤器
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sa-token.