@Configuration
@ComponentScan(basePackages = "com.test.indexer.service")
public class AppConfig {
}
2. 注解调度和定时任务
/**
* 定时任务
*/
@Component
public class ScheduledTasks {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
@Scheduled(fixedRate = 5000)
public void reportCurrentTime() {
System.out.println("------------------The time now is " + dateFormat.format(new Date()));
}
}
3. 调用
@Configuration
@EnableAsync
@EnableScheduling
public class App {
// todo
}
原文:http://www.cnblogs.com/clair-momo/p/6409563.html