shiro异常UnavailableSecurityManagerException
昨天在调程序时出现标题上的异常
查了下好像是说SecurityManager相关问题
后来我看到代码中:
@Bean(name = "securityManager") public SecurityManager securityManager() { DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); //设置自定义realm. securityManager.setRealm(getDatabaseRealm()); //配置记住我 securityManager.setRememberMeManager(rememberMeManager()); SecurityUtils.setSecurityManager(securityManager); return securityManager; }
SecurityUtils.setSecurityManager(securityManager)这一行之前被注释掉了
然后看到SecurityUtils里面
public static SecurityManager getSecurityManager() throws UnavailableSecurityManagerException { SecurityManager securityManager = ThreadContext.getSecurityManager(); if (securityManager == null) { securityManager = securityManager; } if (securityManager == null) { String msg = "No SecurityManager accessible to the calling code, either bound to the " + ThreadContext.class.getName() + " or as a vm static singleton. This is an invalid application configuration."; throw new UnavailableSecurityManagerException(msg); } else { return securityManager; } }
getSecurityManager()正是抛出的该异常
在开头的SecurityManager加入该行异常消失
SecurityUtils.setSecurityManager(securityManager);
后来我想原因可能出现在我在之前代码更改加入了对控制层某方法多线程的处理以及配置:
package com.tansuo365.test1.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.task.TaskExecutor; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import java.util.concurrent.ThreadPoolExecutor; @Configuration @EnableAsync public class AsyncConfig { @Bean public TaskExecutor taskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); // 设置核心线程数 executor.setCorePoolSize(5); // 设置最大线程数 executor.setMaxPoolSize(10); // 设置队列容量 executor.setQueueCapacity(20); // 设置线程活跃时间(秒) executor.setKeepAliveSeconds(60); // 设置默认线程名称 executor.setThreadNamePrefix("danhao-"); // 设置拒绝策略 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 等待所有任务结束后再关闭线程池 executor.setWaitForTasksToCompleteOnShutdown(true); return executor; } }
@Async @RequestMapping("/getChukuNumber") public ListenableFuture<String> genBillCode(String type) throws Exception { StringBuffer billCodeStr = new StringBuffer(); billCodeStr.append(chukudanPrefix); billCodeStr.append(DateUtil.getCurrentDateStr()); String todayMaxChukuDanNumber = chukuZongService.getTodayMaxChukuDanNumber(); if (todayMaxChukuDanNumber != null) { billCodeStr.append(StringUtil.formatCode(todayMaxChukuDanNumber)); } else { billCodeStr.append("0001"); } return new AsyncResult<>(billCodeStr.toString()); // return billCodeStr.toString(); }
如果要启用还要在springboot上加注注解:
//@EnableCaching @SpringBootApplication @MapperScan(value = {"com.xxxxxxx.test1.mapper"}) @EnableAsync//开启异步任务 public class Test1Application { public static void main(String[] args) { SpringApplication.run(Test1Application.class, args); } }
问题结束
相关推荐
杜鲁门 2020-11-05
luckyxl0 2020-08-16
Dullonjiang 2020-08-09
xclxcl 2020-08-03
zmzmmf 2020-08-03
MicroBoy 2020-08-02
ganjing 2020-08-02
likesyour 2020-08-01
zmzmmf 2020-07-09
MicroBoy 2020-07-05
zzhao 2020-06-26
子云 2020-06-18
visionzheng 2020-06-07
neweastsun 2020-06-04
ErixHao 2020-06-03
GDreams0 2020-06-01
ganjing 2020-05-29
zmzmmf 2020-05-28
nullcy 2020-05-26