SaTokenException: Request cannot be obtained in non-web context

Reason for the error: Some APIs of Sa-Token can only be called in the web context. If you report this error, it means that the place where you call Sa-Token is not in the web context. Please check:

  1. Whether the Sa-Token API is called in the main method
  2. Whether the Sa-Token API is called in the @Asyncannotated method
  3. Whether the Sa-Token API is called in some sub-threads that lose the web context, such as MyBatis-Plusthe insertFillautofill of
  4. Whether the Sa-Token API is called in some non-Http protocol RPC frameworks (such as Dubbo)
  5. Whether the Sa-Token API is called in the SpringBoot startup initialization method, for example@PostConstruct

Solution: Get the value you want first, and then pass this value as a parameter to these methods, instead of calling the Sa-Token API directly from the method.

Reference: https://github.com/dromara/sa-token

Supongo que te gusta

Origin blog.csdn.net/shengzhang_/article/details/120320674
Recomendado
Clasificación