我正在从springboot 1.5迁移到2.0。面对问题:
我有配置类:
@Configuration
@EnableScheduling
@EnableAsync(mode = AdviceMode.ASPECTJ)
public class AsyncConfig implements SchedulingConfigurer, AsyncConfigurer
{
@Bean
public EhCacheCleaner ehcacheCleaner()
{
EhCacheCleaner cacheCleaner = new EhCacheCleaner();
cacheCleaner.setCacheManagersNames("hibernateCache", "externalBetCache");
return cacheCleaner;
}
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar)
{
taskRegistrar.setScheduler(taskExecutor());
}
@Bean(destroyMethod = "shutdown")
public ScheduledExecutorService taskExecutor()
{
return Executors.newScheduledThreadPool(2);
}
@Override
public TaskExecutor getAsyncExecutor()
{
return parallelUpdateExternalBetExecutor();
}
@Bean
public TaskExecutor parallelUpdateExternalBetExecutor()
{
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(500);
taskExecutor.setKeepAliveSeconds(10800);
return taskExecutor;
}
@Bean
public TaskExecutor asyncCommonOperation()
{
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(500);
taskExecutor.setKeepAliveSeconds(120);
return taskExecutor;
}
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler()
{
return new SimpleAsyncUncaughtExceptionHandler();
}
}
为什么spring不创建在@Configuration类中定义的bean(调试器不会在其上停止)?但是,如果我删除“ implements SchedulingConfigurer,AsyncConfigurer”,它会按需运行:进入@Bean方法,创建bean。我应该如何解决才能使其正常工作?
谢谢。