Spring-线程池执行save语句报错“ No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton”
报错信息:
Cause: org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
根因:线程池异步调用的时候 应手动绑定SecurityManager 并在结束时释放
注:ThreadContext.bind(securityManager);用try with resource写法 jdk版本 >= 1.9
代码展示:
import org.apache.shiro.mgt.SecurityManager;
@Autowired
private SecurityManager securityManager;
// 手动绑定SecurityManager
ThreadContext.bind(securityManager);
finally {
// 在finally中释放
ThreadContext.unbindSecurityManager();
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 2分钟学会 DeepSeek API,竟然比官方更好用!
· .NET 使用 DeepSeek R1 开发智能 AI 客户端
· 10亿数据,如何做迁移?
· 推荐几款开源且免费的 .NET MAUI 组件库
· c# 半导体/led行业 晶圆片WaferMap实现 map图实现入门篇
2021-11-29 2021129 LeetCode刷题 删除排序链表中的重复元素(难度 :简单)