Yesterday anomaly on the title tune appears in the program
The next check is like saying SecurityManager related issues
Then I saw the code:
@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) before this line is commented out
and see inside 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 () It is the exception thrown
In SecurityManager join the line that begins with the disappearance of abnormal
SecurityUtils.setSecurityManager(securityManager);
Then I think the reason may appear before the code changes I added a method to control layer multi-threaded processing and configuration:
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 = newThe ThreadPoolTaskExecutor is (); // Set the number of core threads executor.setCorePoolSize (. 5 ); // set the maximum number of threads executor.setMaxPoolSize (10 ); // set the queue capacity executor.setQueueCapacity (20 is ); // Set the thread active time (sec ) executor.setKeepAliveSeconds (60 ); // set the default thread name executor.setThreadNamePrefix ( "danhao-" ); // set deny policy executor.setRejectedExecutionHandler ( new new ThreadPoolExecutor.CallerRunsPolicy ()); // wait for all tasks to close before the end of the Thread Pool 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(); }
If you want to enable but also in the springboot filling Note:
//@EnableCaching @SpringBootApplication @MapperScan(value = {"com.xxxxxxx.test1.mapper"}) @EnableAsync//开启异步任务 public class Test1Application { public static void main(String[] args) { SpringApplication.run(Test1Application.class, args); } }
The end of the problem