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:
- Whether the Sa-Token API is called in the main method
- Whether the Sa-Token API is called in the
@Async
annotated method - Whether the Sa-Token API is called in some sub-threads that lose the web context, such as
MyBatis-Plus
theinsertFill
autofill of - Whether the Sa-Token API is called in some non-Http protocol RPC frameworks (such as Dubbo)
- 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