首页 > 代码库 > spring quartz开发中使用demo
spring quartz开发中使用demo
1.首先在pom.xml中配置quartz的jar:
<!--定时器-->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>1.8.5</version>
</dependency>
2.然后在spring-mvc.xml中配置:
<!-- =====================日常任务job========================== -->
<bean id="DailyTaskQtzJob" class="com.geese.inout.util.Quartz">
</bean>
<bean id="DailyTaskQtzJobMethod"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="DailyTaskQtzJob" />
</property>
<property name="targetMethod">
<value>quartz</value>
</property>
</bean>
<!-- ======================== 调度触发器 ======================== -->
<bean id="DailyTaskCronTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="DailyTaskQtzJobMethod"></property>
<!-- 每天下午16:30触发 -->
<property name="cronExpression" value="http://www.mamicode.com/0 38 16 ? * *"></property>
</bean>
<!-- ======================== 调度工厂 ======================== -->
<bean id="SpringJobSchedulerFactoryBean"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="DailyTaskCronTriggerBean" />
</list>
</property>
</bean>
3.最后在对应的util类里面写对应的操作方法,一般就是插入数据到对应的记录表中
spring quartz开发中使用demo