使用@Scheduled時,需要啓動task
啓動方式:
1.使用xml方式,在spring配置文件中添加
<task:annotation-driven>
2.使用spring configuration方式,在配置類即@Configuration下加上@EnableScheduling
@Configuration
@EnableScheduling
@PropertySource({"classpath:application.properties", "classpath:config.properties"})
@EnableTransactionManagement(proxyTargetClass = true)
public class AppConfig {
}
官方文檔:官方文檔地址