Giter Site home page Giter Site logo

Comments (3)

zhuangzibin avatar zhuangzibin commented on June 3, 2024

今天打断点找了下问题,问题就出在响应式中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.

StringKe avatar StringKe commented on June 3, 2024

@zhuangzibin 你解决这个问题了么?通过 deferContextual 或者 contextWrite 这个需要在 response 里才能获取到吧

应该要修改 ServerRequest.bodyToMono 的实现?

from sa-token.

zhuangzibin avatar zhuangzibin commented on June 3, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.