失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Spring框架中的Quartz定时任务使用笔记(通过@Scheduled注解的方式实现)

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

时间:2020-10-02 00:51:45

相关推荐

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

1.修改spring的xml配置信息 applicationContext.xml 三个部分内容

1.xmlns添加:

xmlns:task="/schema/task"

2.xsi:schemaLocation添加:

/schema/task /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;@Servicepublic class QuartzService { //这里有7个时间参数,有不懂的可以直接百度Quartz时间参数详解@Scheduled(cron = "0/2 * * * * *")public void process() {System.out.println("job run...");}}

如果觉得《Spring框架中的Quartz定时任务使用笔记(通过@Scheduled注解的方式实现)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。