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();
}
本文来自博客园,作者:skystrivegao,转载请注明原文链接:https://www.cnblogs.com/skystrive/p/18567585
整理不易,如果对您有所帮助 请点赞收藏,谢谢~