Quartz的使用总结
something: 个人对于Quartz框架也是刚刚接触,理解并不深,下面分享两篇关于Quartz的文章-个人觉得写的非常棒!
补充: spring简单整合Quartz的配置文件applicationContext-job.xml
添加quartz依赖
<dependency>
<groupId>org.quartz-scheduler</group>
<artifactId>quartz</artifactId>
<version>2.2.3</version>
</dependency>
spring配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
">
<!-- 定义一个任务类 -->
<bean id="job" class="cn.muzile.job.Job">
</bean>
<!-- 任务类描述 -->
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="job"></property>
<!-- value:任务方法名 -->
<property name="targetMethod" value="dojob"></property>
</bean>
<!-- 触发器 -->
<bean id="trigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail"></property>
<!--触发时间cron表达式, 七子表达式. 7个域 -->
<!-- 每天上午12:20分和下午16:20执行 -->
<property name="cronExpression" value="0 20 12,16 * * ?"></property>
</bean>
<!-- 任务调度管理容器 -->
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name="triggers">
<list>
<ref bean="trigger"/>
</list>
</property>
</bean>
</beans>