使用@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 {
}
官方文档:官方文档地址