目前采用的工程为maven工程
src/main/java
|--jobsSchedule.java
src/main/resouces
|--schedule.properties
|--spring-Context.xml
src/test/java
src/test/resouces
spring-Context.xml中以注解的方式配置定时任务
<task:excutor id="excutor" pool-size="10"/><task:scheduler id="scheduler" pool-size="10"/>
<task:annotation-driven scheduler="scheduler" excutor="excutor" proxy-target-class="true"/>
在schedule.properties中定义好
jobs.runTime = 0 0 0 0 25 *?
#每个月25号24点跑这个定时任务。秒 分 时 天 月 年* * * * * *
使用注解方式在jobsSchdule.java中配置时间
@Service @Lazy(false)
@PropertySource("classpath:schedule.properties")
public class jobsSchedule{
//方法
@schedule(cron="${jobs.runTime}")
public void runForest(){
System.out.println("Forest run!!!");
}
}