需要配置的项:
1,spring- context.xml 下的包扫描:component-scan :将 设置定时方法所在的类的包加入自动扫描的目录里。
2.spring- context.xml 添加 <task:annotation-driven/>
3.编写定时方法: 1.在该方法所属的类下 加入注解 @Component 在该方法上 加入注解 @Scheduled(cron="*/20 * * * * ? ")//二十秒执行一次
eg:
/**
* @author liuyuanjing 2016-01-08
* 设置执行点击率持久化的定时器*/
@Component
public class ClickRateTimeToPersistence {
//设置定时执行
@Scheduled(cron="*/20 * * * * ? ") //二十秒执行一次
public void main(){
system.out.println(1);
}
}