任何人都可以解釋如何使用@Scheduled註釋實現任務的基本配置而無需任何XML配置?我可以找到的所有示例至少使用最少的XML配置。例如:註解驅動任務的Spring @Configuration(非xml配置)
http://blog.springsource.com/2010/01/05/task-scheduling-simplifications-in-spring-3-0/
它使用一個典型:
<context:component-scan base-package="org/springframework/samples/task/basic/annotation"/>
<task:annotation-driven/>
所以我只是用@Configuration註釋與一羣@Bean註解。它們都在啓動時實例化,但帶有@Scheduled的那個不運行。過去,在使用XML配置時,我已經成功地使用了該註釋,但從未僅使用註釋。
請注意,即使我的鏈接是3.1文檔,ScheduledAnnotationBeanPostProcessor也存在3.0。 – Kevin
是聲明\ @Configuration類中的ScheduledAnnotationBeanPostProcessor,因爲\ @Bean似乎有效 - 意味着它完成了任務:註釋驅動的任務。 – david