(1):修改配置 文件 如下:
<!-- 注解扫描包 -->
<task:annotation-driven/><!-- 用定时器注解 -->
<context:component-scan base-package="com.xx.controller" />
<context:component-scan base-package="com.xx.scheduler" /> <!-- 用定时器 --></span>
package com.xx.scheduler;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class Job {
public Job(){
System.out.println("MyJob创建成功");
}
@Scheduled(cron = "0/1 * * * * ? ")//每隔1秒隔行一次
public void run(){
System.out.println("Hello MyJob "+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ").format(new Date()));
}
}