谁能解释如何使用 @Scheduled 注释实现任务的基本配置而不需要任何 XML 配置?我能找到的所有示例都至少使用最少的 XML 配置。例如:
http://blog.springsource.com/2010/01/05/task-scheduling-simplifications-in-spring-3-0/ 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 配置时成功地使用了该注释,但从未仅使用注释。
只需在 WebMvcConfig 类上添加 @EnableScheduling
@Configuration
@EnableWebMvc
@EnableAsync
@EnableScheduling
public class WebMvcConfig extends WebMvcConfigurerAdapter {
/** Annotations config Stuff ... **/
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)