1.修改spring的xml配置信息 applicationContext.xml 三个部分内容
1.xmlns添加:
xmlns:task="http://www.springframework.org/schema/task"
2.xsi:schemaLocation添加:
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
3.applicationContext.xml中添加:
<task:annotation-driven/>
2.最后编写需要定时执行的方法即可,加上对应的注解
package spring.demo.service; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @Service public class QuartzService { //这里有7个时间参数,有不懂的可以直接百度Quartz时间参数详解 @Scheduled(cron = "0/2 * * * * *") public void process() { System.out.println("job run..."); } }