shiro放到异步线程中执行时会报这个错,放到线程外就正常了,错误如下
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.
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.
代码如下:
出错代码:
// 保存日志
//创建异步任务
Task task = new Task()
{
@Override
public void run()
{
// 封装对象
SpringContextHolder.getBean(IOperationLogService.class).insert(operationLog);
}
};
// 运行任务
SpringContextHolder.getBean(TaskHelper.class).doTask(task);
正常执行代码:
IOperationLogService operationLogService = SpringContextHolder.getBean(IOperationLogService.class);
operationLogService.insert(operationLog);