1、在spring配置文件中添加如下代码(命名空间)
xmlns:task="http://www.springframework.org/schema/task
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd
2、spring配置文件中配置定时任务
<!--定时任务-->
<task:annotation-driven/>
<context:annotation-config/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<context:component-scan base-package="com.project.service"/>
3、在对应的包中添加定时任务(定时任务的表达式可以自己百度)
@Service
public class ScheduleService {
@Scheduled(cron = "0/5 * * * * ?")
public void scheduleTest(){
System.out.println("==========this is my schedual===========");
}
}