春季计划任务未触发 [英] Spring scheduled tasks not firing

查看:55
本文介绍了春季计划任务未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自学Spring,目前在计划任务上,下面的代码没有触发计划任务.

我相信这与我设置 Spring 上下文的方式有关,但这只是一个猜测 - 我正在尝试学习 Spring,所以请原谅可笑的 while 循环.

Application.java:

包你好;导入 org.springframework.context.annotation.AnnotationConfigApplicationContext;公共类应用{public static void main(String[] args) 抛出异常 {AnnotationConfigApplicationContext rootContext =新的 AnnotationConfigApplicationContext();rootContext.register(RootContextConfiguration.class);rootContext.refresh();while(rootContext != null) {尝试 {线程睡眠(2500);} catch(InterruptedException ex) {Thread.currentThread().interrupt();}System.out.println("循环\n");}rootContext.close();}}

RootContextConfiguration.java:

包你好;导入 java.util.concurrent.Executor;导入 org.springframework.context.annotation.AdviceMode;导入 org.springframework.context.annotation.Bean;导入 org.springframework.context.annotation.ComponentScan;导入 org.springframework.context.annotation.Configuration;导入 org.springframework.core.Ordered;导入 org.springframework.scheduling.TaskScheduler;导入 org.springframework.scheduling.annotation.AsyncConfigurer;导入 org.springframework.scheduling.annotation.EnableAsync;导入 org.springframework.scheduling.annotation.EnableScheduling;导入 org.springframework.scheduling.annotation.SchedulingConfigurer;导入 org.springframework.scheduling.concurrent.ThreadPoolTask​​Scheduler;导入 org.springframework.scheduling.config.ScheduledTaskRegistrar;@配置@EnableScheduling@启用异步(模式 = AdviceMode.PROXY,proxyTargetClass = false,order = Ordered.HIGHEST_PRECEDENCE)@组件扫描(basePackages = "你好")公共类 RootContextConfiguration 实现AsyncConfigurer、SchedulingConfigurer {@豆角,扁豆公共线程池任务调度器 taskScheduler(){ThreadPoolTask​​Scheduler 调度器 = new ThreadPoolTask​​Scheduler();scheduler.setPoolSize(20);scheduler.setThreadNamePrefix("task-");scheduler.setAwaitTerminationSeconds(60);scheduler.setWaitForTasksToCompleteOnShutdown(true);返回调度器;}@覆盖公共执行器 getAsyncExecutor(){Executor executor = this.taskScheduler();返回执行器;}@覆盖public void configureTasks(ScheduledTaskRegistrar 注册器){TaskScheduler 调度程序 = this.taskScheduler();registrar.setTaskScheduler(scheduler);}}

ScheduledTasks.java:

包你好;导入 java.text.SimpleDateFormat;导入 java.util.Date;导入 org.springframework.scheduling.annotation.EnableScheduling;导入 org.springframework.scheduling.annotation.Scheduled;@EnableScheduling公共类计划任务{private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");@Scheduled(fixedRate = 5000)公共无效报告当前时间(){System.out.println("现在是时间" + dateFormat.format(new Date()));}}

pom.xml:

<modelVersion>4.0.0</modelVersion><groupId>org.springframework</groupId><artifactId>gs-scheduling-tasks</artifactId><version>0.1.0</version><父母><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.0.2.RELEASE</version></父母><依赖项><依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></依赖></依赖项><属性><start-class>hello.Application</start-class></属性><构建><插件><插件><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version></插件><插件><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></插件></plugins></build><存储库><存储库><id>弹簧快照</id><name>Spring 快照</name><url>http://repo.spring.io/libs-snapshot</url><快照><已启用>真</已启用></快照></repository></repositories><插件库><插件库><id>弹簧快照</id><name>Spring 快照</name><url>http://repo.spring.io/libs-snapshot</url><快照><已启用>真</已启用></快照></pluginRepository></pluginRepositories></项目>

这是我在终端中看到的:

12:32:36.533 [main] DEBUG o.s.core.env.StandardEnvironment - 添加具有最低搜索优先级的 [systemProperties] PropertySource12:32:36.541 [main] DEBUG o.s.core.env.StandardEnvironment - 添加具有最低搜索优先级的 [systemEnvironment] PropertySource12:32:36.542 [main] DEBUG o.s.core.env.StandardEnvironment - 使用 PropertySources 初始化 StandardEnvironment [systemProperties,systemEnvironment]12:32:36.657 [main] INFO o.s.c.a.AnnotationConfigApplicationContext - 刷新 org.springframework.context.annotation.AnnotationConfigApplicationContext@7a46a697:启动日期 [2014 年 4 月 25 日星期五 12:32:36 PDT];上下文层次结构的根12:32:36.663 [main] 调试 oscaAnnotationConfigApplicationContext - org.springframework.context.annotation.AnnotationConfigApplicationContext@7a46a697 的 Bean 工厂:org.springframework.beans.factory.support.DefaultListableBeanFactory@2038ae61:定义 beans.context.annotation.AnnotationConfigApplicationContext@7a46a697annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,rootContextConfiguration];工厂层次结构的根12:32:36.691 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建单例 bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' 的共享实例12:32:36.692 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建 bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' 的实例12:32:36.725 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 急切地缓存 bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' 以允许解决潜在的循环引用12:32:36.728 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 完成创建 bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' 的实例12:32:36.789 [main] DEBUG o.s.core.env.StandardEnvironment - 添加具有最低搜索优先级的 [systemProperties] PropertySource12:32:36.790 [main] DEBUG o.s.core.env.StandardEnvironment - 添加具有最低搜索优先级的 [systemEnvironment] PropertySource12:32:36.791 [main] DEBUG o.s.core.env.StandardEnvironment - 使用 PropertySources 初始化 StandardEnvironment [systemProperties,systemEnvironment]12:32:36.799 [main] DEBUG o.s.c.i.s.PathMatchingResourcePatternResolver - 在目录树中寻找匹配的资源 [/Users/cthielen/src/spring/scheduled-tasks/target/classes/hello]12:32:36.799 [main] DEBUG oscisPathMatchingResourcePatternResolver - 搜索目录 [/Users/cthielen/src/spring/scheduled-tasks/target/classes/hello] 文件匹配模式 [/Users/cthielen/src/spring/scheduled-任务/目标/类/你好/**/*.class]12:32:36.803 [main] DEBUG oscisPathMatchingResourcePatternResolver - 解析位置模式 [classpath*:hello/**/*.class] 到资源 [file [/Users/cthielen/src/spring/scheduled-tasks/target/classes/hello/Application.class],文件[/Users/cthielen/src/spring/scheduled-tasks/target/classes/hello/RootContextConfiguration.class],文件[/Users/cthielen/src/spring/scheduled-tasks/target/类/你好/ScheduledTasks.class]]12:32:36.941 [main] DEBUG o.s.c.a.ConfigurationClassBeanDefinitionReader - 为导入的@Configuration 类 org.springframework.scheduling.annotation.SchedulingConfiguration 注册的 bean 定义12:32:36.944 [main] DEBUG o.s.c.a.ConfigurationClassBeanDefinitionReader - 注册 @Bean 方法 org.springframework.scheduling.annotation.SchedulingConfiguration.org.springframework.context.annotation.internalScheduledAnnotationProcessor() 的 bean 定义12:32:36.945 [main] DEBUG o.s.c.a.ConfigurationClassBeanDefinitionReader - 为导入的@Configuration 类 org.springframework.scheduling.annotation.ProxyAsyncConfiguration 注册的 bean 定义12:32:36.946 [main] DEBUG o.s.c.a.ConfigurationClassBeanDefinitionReader - 注册 @Bean 方法 org.springframework.scheduling.annotation.ProxyAsyncConfiguration.org.springframework.context.annotation.internalAsyncAnnotationProcessor() 的 bean 定义12:32:36.950 [main] DEBUG o.s.c.a.ConfigurationClassBeanDefinitionReader - 为@Bean 方法 hello.RootContextConfiguration.taskScheduler() 注册 bean 定义12:32:37.056 [main] DEBUG o.s.c.a.ConfigurationClassEnhancer - 成功增强 hello.RootContextConfiguration;增强类名称为:hello.RootContextConfiguration$$EnhancerBySpringCGLIB$$723fae6112:32:37.056 [main] DEBUG o.s.c.a.ConfigurationClassPostProcessor - 用增强的类名 'hello.RootContextConfiguration$$EnhancerBySpringCGLIB$$723fae61' 替换 bean 定义 'rootContextConfiguration' 现有类名 'hello.RootContextConfiguration'12:32:37.060 [main] DEBUG o.s.c.a.ConfigurationClassEnhancer - 成功增强 org.springframework.scheduling.annotation.SchedulingConfiguration;增强类名称是:org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerBySpringCGLIB$$4cc1c8d212:32:37.061 [main] DEBUG oscaConfigurationClassPostProcessor - 替换 bean 定义 'org.springframework.scheduling.annotation.SchedulingConfiguration' 现有类名 'org.springframework.scheduling.annotation.SchedulingConfiguration' 与增强的类名 'org.springframework.schedulingConfiguration'.annotation.SchedulingConfiguration$$EnhancerBySpringCGLIB$$4cc1c8d2'12:32:37.071 [main] DEBUG o.s.c.a.ConfigurationClassEnhancer - 成功增强 org.springframework.scheduling.annotation.ProxyAsyncConfiguration;增强类名称是:org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$18e9d43812:32:37.072 [main] DEBUG oscaConfigurationClassPostProcessor - 用增强的类名org.springframework.scheduling"替换 bean 定义org.springframework.scheduling.annotation.ProxyAsyncConfiguration"现有类名org.springframework.scheduling.annotation.ProxyAsyncConfiguration".annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$18e9d438'12:32:37.086 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建单例 bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' 的共享实例12:32:37.088 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建 bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' 的实例12:32:37.089 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 急切地缓存 bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' 以允许解决潜在的循环引用12:32:37.090 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 完成创建 bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' 的实例12:32:37.090 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建单例 bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' 的共享实例12:32:37.090 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建 bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' 的实例12:32:37.091 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 急切地缓存 bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' 以允许解决潜在的循环引用12:32:37.091 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 完成创建 bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' 的实例12:32:37.091 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建单例 bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' 的共享实例12:32:37.092 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建 bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' 的实例12:32:37.096 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 急切地缓存 bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' 以允许解决潜在的循环引用12:32:37.098 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 完成创建 bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' 的实例12:32:37.098 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建单例 bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor' 的共享实例12:32:37.098 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建 bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor' 的实例12:32:37.099 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 急切地缓存 bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor' 以允许解决潜在的循环引用12:32:37.099 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 完成创建 bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor' 的实例12:32:37.099 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建单例 bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor' 的共享实例12:32:37.100 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建 bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor' 的实例12:32:37.100 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 急切地缓存 bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor' 以允许解决潜在的循环引用12:32:37.100 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 完成创建 bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor' 的实例12:32:37.102 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建单例 bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor' 的共享实例12:32:37.102 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建 bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor' 的实例12:32:37.105 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建单例 bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' 的共享实例12:32:37.105 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建 bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' 的实例12:32:37.122 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 急切地缓存 bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' 以允许解决潜在的循环引用12:32:37.168 [main] INFO oscsPostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' 类型 [class org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerBy4Spring1CGLIB$]被所有 BeanPostProcessor 处理(例如:不符合自动代理的条件)12:32:37.168 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 完成创建 bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' 的实例12:32:37.253 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 急切地缓存 bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor' 以允许解决潜在的循环引用12:32:37.258 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 完成创建 bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor' 的实例12:32:37.259 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建单例 bean 'org.springframework.context.annotation.internalAsyncAnnotationProcessor' 的共享实例12:32:37.259 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建 bean 'org.springframework.context.annotation.internalAsyncAnnotationProcessor' 的实例12:32:37.259 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建单例 bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' 的共享实例12:32:37.259 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建 bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' 的实例12:32:37.265 [main] DEBUG osbfannotation.InjectionMetadata - 在类 [org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$18e9d438] 上注册注入的元素:AutowiredMethodElement for void org.springframework.scheduling.scheduling.schedulation.schedulingsetConfigurers(java.util.Collection)12:32:37.265 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 急切地缓存 bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' 以允许解决潜在的循环引用12:32:37.268 [main] 调试 osbfannotation.InjectionMetadata - 处理 bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' 的注入方法:AutowiredMethodElement for void org.springframework.scheduling.annotation.AbstractAsyncConfiguration.setConfigurers(java.springframework.scheduling.annotation.ProxyAsyncConfiguration': AutowiredMethodElement收藏)12:32:37.273 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建单例 bean 'rootContextConfiguration' 的共享实例12:32:37.273 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建 bean 'rootContextConfiguration' 的实例12:32:37.275 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 急切地缓存 bean 'rootContextConfiguration' 以允许解决潜在的循环引用12:32:37.278 [main] INFO oscsPostProcessorRegistrationDelegate$BeanPostProcessorChecker - [class hello.RootContextConfiguration$$EnhancerBySpringCGLIB$$723fae61] 类型的 Bean 'rootContextConfiguration' 不符合被所有 BeanPostProcessor 处理的条件(例如:不符合自动处理的条件)代理)12:32:37.279 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 完成创建 bean 'rootContextConfiguration' 的实例12:32:37.290 [main] DEBUG o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - 按类型自动装配从 bean 名称org.springframework.scheduling.annotation.ProxyAsyncConfiguration"到名为rootContextConfiguration"的 bean12:32:37.291 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建单例 bean 'taskScheduler' 的共享实例12:32:37.291 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 创建 bean 'taskScheduler' 的实例12:32:37.291 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'rootContextConfiguration' 的缓存实例12:32:37.308 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 急切地缓存 bean 'taskScheduler' 以允许解决潜在的循环引用12:32:37.336 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 在名为taskScheduler"的 bean 上调用 afterPropertiesSet()12:32:37.338 [main] 信息 o.s.s.c.ThreadPoolTask​​Scheduler - 初始化 ExecutorService 'taskScheduler'12:32:37.342 [main] INFO oscsPostProcessorRegistrationDelegate$BeanPostProcessorChecker - [class org.springframework.scheduling.concurrent.ThreadPoolTask​​Scheduler] 类型的 Bean 'taskScheduler' 不符合被所有 BeanPostProcessor 处理的条件(例如:不符合自动处理的条件)代理)12:32:37.342 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 完成创建 bean 'taskScheduler' 的实例12:32:37.342 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' 的缓存实例12:32:37.345 [main] INFO oscsPostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' 类型 [class org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBy18CGLIB] 不符合条件 3被所有 BeanPostProcessor 处理(例如:不符合自动代理的条件)12:32:37.345 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 完成创建 bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' 的实例12:32:37.385 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 急切地缓存 bean 'org.springframework.context.annotation.internalAsyncAnnotationProcessor' 以允许解决潜在的循环引用12:32:37.413 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 完成创建 bean 'org.springframework.context.annotation.internalAsyncAnnotationProcessor' 的实例12:32:37.435 [main] DEBUG o.s.c.a.AnnotationConfigApplicationContext - 无法找到名为messageSource"的 MessageSource:使用默认 [org.springframework.context.support.DelegatingMessageSource@3c72f59f]12:32:37.440 [main] DEBUG o.s.c.a.AnnotationConfigApplicationContext - 无法找到名称为applicationEventMulticaster"的 ApplicationEventMulticaster:使用默认 [org.springframework.context.event.SimpleApplicationEventMulticaster@12d4bf7e]12:32:37.454 [main] 调试 osbfsDefaultListableBeanFactory - 在 org.springframework.beans.factory.support.DefaultListableBeanFactory@2038ae61 中预实例化单例:定义 bean [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework]annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,rootContextConfiguration,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.scheduling.annotation.SchedulingConfiguration,org.springframework.context.annotation.internalScheduledAnnotationProcessor,org.springframework.scheduling.annotation.ProxyAsyncConfiguration,org.springframework.context.annotation.internalAsyncAnnotationProcessor,taskS调度器];工厂层次结构的根12:32:37.455 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' 的缓存实例12:32:37.455 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' 的缓存实例12:32:37.455 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' 的缓存实例12:32:37.456 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' 的缓存实例12:32:37.459 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'rootContextConfiguration' 的缓存实例12:32:37.460 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor' 的缓存实例12:32:37.461 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor' 的缓存实例12:32:37.461 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' 的缓存实例12:32:37.461 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor' 的缓存实例12:32:37.461 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' 的缓存实例12:32:37.461 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'org.springframework.context.annotation.internalAsyncAnnotationProcessor' 的缓存实例12:32:37.461 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'taskScheduler' 的缓存实例12:32:37.463 [main] DEBUG o.s.c.a.AnnotationConfigApplicationContext - 无法找到名为lifecycleProcessor"的 LifecycleProcessor:使用默认 [org.springframework.context.support.DefaultLifecycleProcessor@2928854b]12:32:37.463 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'lifecycleProcessor' 的缓存实例12:32:37.464 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor' 的缓存实例12:32:37.465 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'rootContextConfiguration' 的缓存实例12:32:37.465 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - 返回单例 bean 'taskScheduler' 的缓存实例12:32:37.481 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - 在 [systemProperties] 中搜索键spring.liveBeansView.mbeanDomain"12:32:37.482 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - 在 [systemEnvironment] 中搜索键spring.liveBeansView.mbeanDomain"12:32:37.482 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - 在任何属性源中找不到键spring.liveBeansView.mbeanDomain".返回 [空]环形环形环形环形

明确地说,睡眠 2.5 秒并打印循环"只是为了让应用程序运行以查看计划任务是否触发.

我正在寻找的是打印触发时间的计划任务.没有.

预先感谢您提供的任何帮助.

解决方案

您没有 ScheduledTasks bean.使用 @Component(或其任何特化)注释您的类,或在您的 @Configuration 类中为其声明一个 @Bean 方法.<小时>

@EnableScheduling 属于 @Configuration 类,而不属于具有预定行为的类.您可以从 ScheduledTasks 中删除它.

I'm teaching myself Spring, currently on scheduled tasks, and the following code does not fire the scheduled task.

I believe it has something to do with the way I'm setting up the Spring context but that's only a guess - I'm trying to learn Spring so please excuse the ridiculous while loop.

Application.java:

package hello;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Application {

    public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext rootContext =
                        new AnnotationConfigApplicationContext();

        rootContext.register(RootContextConfiguration.class);
        rootContext.refresh();

        while(rootContext != null) {
            try {
                Thread.sleep(2500);
            } catch(InterruptedException ex) {
                Thread.currentThread().interrupt();
            }

            System.out.println("Loop\n");
        }

        rootContext.close();
    }
}

RootContextConfiguration.java:

package hello;

import java.util.concurrent.Executor;

import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

@Configuration
@EnableScheduling
@EnableAsync(
        mode = AdviceMode.PROXY, proxyTargetClass = false,
        order = Ordered.HIGHEST_PRECEDENCE
)
@ComponentScan(
        basePackages = "hello"
)
public class RootContextConfiguration implements
AsyncConfigurer, SchedulingConfigurer {
    @Bean
    public ThreadPoolTaskScheduler taskScheduler()
    {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.setPoolSize(20);
        scheduler.setThreadNamePrefix("task-");
        scheduler.setAwaitTerminationSeconds(60);
        scheduler.setWaitForTasksToCompleteOnShutdown(true);
        return scheduler;
    }

    @Override
    public Executor getAsyncExecutor()
    {
        Executor executor = this.taskScheduler();
        return executor;
    }

    @Override
    public void configureTasks(ScheduledTaskRegistrar registrar)
    {
        TaskScheduler scheduler = this.taskScheduler();
        registrar.setTaskScheduler(scheduler);
    }
}

ScheduledTasks.java:

package hello;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@EnableScheduling
public class ScheduledTasks {

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    @Scheduled(fixedRate = 5000)
    public void reportCurrentTime() {
        System.out.println("The time is now " + dateFormat.format(new Date()));
    }
}

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>gs-scheduling-tasks</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.0.2.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
    </dependencies>

    <properties>
        <start-class>hello.Application</start-class>
    </properties>

    <build>
        <plugins>
            <plugin> 
                <artifactId>maven-compiler-plugin</artifactId> 
                <version>2.3.2</version> 
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>http://repo.spring.io/libs-snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>http://repo.spring.io/libs-snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>

Here's what I see in my terminal:

12:32:36.533 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
12:32:36.541 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
12:32:36.542 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
12:32:36.657 [main] INFO  o.s.c.a.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@7a46a697: startup date [Fri Apr 25 12:32:36 PDT 2014]; root of context hierarchy
12:32:36.663 [main] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Bean factory for org.springframework.context.annotation.AnnotationConfigApplicationContext@7a46a697: org.springframework.beans.factory.support.DefaultListableBeanFactory@2038ae61: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,rootContextConfiguration]; root of factory hierarchy
12:32:36.691 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
12:32:36.692 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
12:32:36.725 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' to allow for resolving potential circular references
12:32:36.728 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
12:32:36.789 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
12:32:36.790 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
12:32:36.791 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
12:32:36.799 [main] DEBUG o.s.c.i.s.PathMatchingResourcePatternResolver - Looking for matching resources in directory tree [/Users/cthielen/src/spring/scheduled-tasks/target/classes/hello]
12:32:36.799 [main] DEBUG o.s.c.i.s.PathMatchingResourcePatternResolver - Searching directory [/Users/cthielen/src/spring/scheduled-tasks/target/classes/hello] for files matching pattern [/Users/cthielen/src/spring/scheduled-tasks/target/classes/hello/**/*.class]
12:32:36.803 [main] DEBUG o.s.c.i.s.PathMatchingResourcePatternResolver - Resolved location pattern [classpath*:hello/**/*.class] to resources [file [/Users/cthielen/src/spring/scheduled-tasks/target/classes/hello/Application.class], file [/Users/cthielen/src/spring/scheduled-tasks/target/classes/hello/RootContextConfiguration.class], file [/Users/cthielen/src/spring/scheduled-tasks/target/classes/hello/ScheduledTasks.class]]
12:32:36.941 [main] DEBUG o.s.c.a.ConfigurationClassBeanDefinitionReader - Registered bean definition for imported @Configuration class org.springframework.scheduling.annotation.SchedulingConfiguration
12:32:36.944 [main] DEBUG o.s.c.a.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method org.springframework.scheduling.annotation.SchedulingConfiguration.org.springframework.context.annotation.internalScheduledAnnotationProcessor()
12:32:36.945 [main] DEBUG o.s.c.a.ConfigurationClassBeanDefinitionReader - Registered bean definition for imported @Configuration class org.springframework.scheduling.annotation.ProxyAsyncConfiguration
12:32:36.946 [main] DEBUG o.s.c.a.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method org.springframework.scheduling.annotation.ProxyAsyncConfiguration.org.springframework.context.annotation.internalAsyncAnnotationProcessor()
12:32:36.950 [main] DEBUG o.s.c.a.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method hello.RootContextConfiguration.taskScheduler()
12:32:37.056 [main] DEBUG o.s.c.a.ConfigurationClassEnhancer - Successfully enhanced hello.RootContextConfiguration; enhanced class name is: hello.RootContextConfiguration$$EnhancerBySpringCGLIB$$723fae61
12:32:37.056 [main] DEBUG o.s.c.a.ConfigurationClassPostProcessor - Replacing bean definition 'rootContextConfiguration' existing class name 'hello.RootContextConfiguration' with enhanced class name 'hello.RootContextConfiguration$$EnhancerBySpringCGLIB$$723fae61'
12:32:37.060 [main] DEBUG o.s.c.a.ConfigurationClassEnhancer - Successfully enhanced org.springframework.scheduling.annotation.SchedulingConfiguration; enhanced class name is: org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerBySpringCGLIB$$4cc1c8d2
12:32:37.061 [main] DEBUG o.s.c.a.ConfigurationClassPostProcessor - Replacing bean definition 'org.springframework.scheduling.annotation.SchedulingConfiguration' existing class name 'org.springframework.scheduling.annotation.SchedulingConfiguration' with enhanced class name 'org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerBySpringCGLIB$$4cc1c8d2'
12:32:37.071 [main] DEBUG o.s.c.a.ConfigurationClassEnhancer - Successfully enhanced org.springframework.scheduling.annotation.ProxyAsyncConfiguration; enhanced class name is: org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$18e9d438
12:32:37.072 [main] DEBUG o.s.c.a.ConfigurationClassPostProcessor - Replacing bean definition 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' existing class name 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' with enhanced class name 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$18e9d438'
12:32:37.086 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
12:32:37.088 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
12:32:37.089 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' to allow for resolving potential circular references
12:32:37.090 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
12:32:37.090 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
12:32:37.090 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
12:32:37.091 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' to allow for resolving potential circular references
12:32:37.091 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
12:32:37.091 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
12:32:37.092 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
12:32:37.096 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' to allow for resolving potential circular references
12:32:37.098 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
12:32:37.098 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
12:32:37.098 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
12:32:37.099 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor' to allow for resolving potential circular references
12:32:37.099 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
12:32:37.099 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor'
12:32:37.100 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor'
12:32:37.100 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor' to allow for resolving potential circular references
12:32:37.100 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor'
12:32:37.102 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'
12:32:37.102 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'
12:32:37.105 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.scheduling.annotation.SchedulingConfiguration'
12:32:37.105 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.scheduling.annotation.SchedulingConfiguration'
12:32:37.122 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' to allow for resolving potential circular references
12:32:37.168 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' of type [class org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerBySpringCGLIB$$4cc1c8d2] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
12:32:37.168 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.scheduling.annotation.SchedulingConfiguration'
12:32:37.253 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor' to allow for resolving potential circular references
12:32:37.258 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'
12:32:37.259 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAsyncAnnotationProcessor'
12:32:37.259 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalAsyncAnnotationProcessor'
12:32:37.259 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration'
12:32:37.259 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration'
12:32:37.265 [main] DEBUG o.s.b.f.annotation.InjectionMetadata - Registered injected element on class [org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$18e9d438]: AutowiredMethodElement for void org.springframework.scheduling.annotation.AbstractAsyncConfiguration.setConfigurers(java.util.Collection)
12:32:37.265 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' to allow for resolving potential circular references
12:32:37.268 [main] DEBUG o.s.b.f.annotation.InjectionMetadata - Processing injected method of bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration': AutowiredMethodElement for void org.springframework.scheduling.annotation.AbstractAsyncConfiguration.setConfigurers(java.util.Collection)
12:32:37.273 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'rootContextConfiguration'
12:32:37.273 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'rootContextConfiguration'
12:32:37.275 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'rootContextConfiguration' to allow for resolving potential circular references
12:32:37.278 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'rootContextConfiguration' of type [class hello.RootContextConfiguration$$EnhancerBySpringCGLIB$$723fae61] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
12:32:37.279 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'rootContextConfiguration'
12:32:37.290 [main] DEBUG o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - Autowiring by type from bean name 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' to bean named 'rootContextConfiguration'
12:32:37.291 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'taskScheduler'
12:32:37.291 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'taskScheduler'
12:32:37.291 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'rootContextConfiguration'
12:32:37.308 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'taskScheduler' to allow for resolving potential circular references
12:32:37.336 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'taskScheduler'
12:32:37.338 [main] INFO  o.s.s.c.ThreadPoolTaskScheduler - Initializing ExecutorService  'taskScheduler'
12:32:37.342 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'taskScheduler' of type [class org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
12:32:37.342 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'taskScheduler'
12:32:37.342 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry'
12:32:37.345 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' of type [class org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$18e9d438] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
12:32:37.345 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration'
12:32:37.385 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalAsyncAnnotationProcessor' to allow for resolving potential circular references
12:32:37.413 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalAsyncAnnotationProcessor'
12:32:37.435 [main] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@3c72f59f]
12:32:37.440 [main] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@12d4bf7e]
12:32:37.454 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2038ae61: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,rootContextConfiguration,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor,org.springframework.scheduling.annotation.SchedulingConfiguration,org.springframework.context.annotation.internalScheduledAnnotationProcessor,org.springframework.scheduling.annotation.ProxyAsyncConfiguration,org.springframework.context.annotation.internalAsyncAnnotationProcessor,taskScheduler]; root of factory hierarchy
12:32:37.455 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
12:32:37.455 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
12:32:37.455 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
12:32:37.456 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
12:32:37.459 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'rootContextConfiguration'
12:32:37.460 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
12:32:37.461 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor'
12:32:37.461 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.scheduling.annotation.SchedulingConfiguration'
12:32:37.461 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'
12:32:37.461 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration'
12:32:37.461 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalAsyncAnnotationProcessor'
12:32:37.461 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'taskScheduler'
12:32:37.463 [main] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@2928854b]
12:32:37.463 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
12:32:37.464 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'
12:32:37.465 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'rootContextConfiguration'
12:32:37.465 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'taskScheduler'
12:32:37.481 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemProperties]
12:32:37.482 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]
12:32:37.482 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source. Returning [null]
Loop

Loop

Loop

Loop

To be clear, the sleeping for 2.5s and print "Loop" is just there to keep the application running to see if the scheduled tasks fire.

What I'm looking for is the scheduled task which prints the time to fire. It does not.

Thanks in advance for any help you can offer.

解决方案

You don't have a ScheduledTasks bean. Annotate your class with @Component (or any of its specializations) or declare a @Bean method for it in your @Configuration class.


@EnableScheduling belongs on a @Configuration class, not on the class which has the scheduled behavior. You can remove it from ScheduledTasks.

这篇关于春季计划任务未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆