您的位置:首页 > 编程语言 > Java开发

Spring框架中的Quartz定时任务使用笔记(通过@Scheduled注解的方式实现)

2018-03-22 13:09 691 查看

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...");
}

}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐