Spring+quartz 做定时任务时,每5分种执行一次,怎么写法
2个回答
展开全部
cron表达式为“0 0/5 * * * ?”
推荐使用maven构建项目,如果你的quartz的版本为2.2.1及以上,
主要的spring applicationContext bean配置如下【2.2版本后配置有些变化】:
bean id="jobDetail"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="cn.javacoder.test.quartz.HelloJob"/>
<property name="durability" value="true"/>
</bean>
<bean id="trigger_test" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail"/>
<property name="cronExpression" value="0 0/5 * * * ?"/>
</bean>
<bean id="startQuertz" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="configLocation" value="classpath:quartz.properties" />
<property name="triggers">
<list>
<ref bean="trigger_test" />
</list>
</property>
<property name="dataSource" ref="dataSource"/>
<property name="waitForJobsToCompleteOnShutdown" value="true"/>
</bean>
具体可以参考我的博客: http://www.javacoder.cn/?p=546
推荐使用maven构建项目,如果你的quartz的版本为2.2.1及以上,
主要的spring applicationContext bean配置如下【2.2版本后配置有些变化】:
bean id="jobDetail"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="cn.javacoder.test.quartz.HelloJob"/>
<property name="durability" value="true"/>
</bean>
<bean id="trigger_test" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail"/>
<property name="cronExpression" value="0 0/5 * * * ?"/>
</bean>
<bean id="startQuertz" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="configLocation" value="classpath:quartz.properties" />
<property name="triggers">
<list>
<ref bean="trigger_test" />
</list>
</property>
<property name="dataSource" ref="dataSource"/>
<property name="waitForJobsToCompleteOnShutdown" value="true"/>
</bean>
具体可以参考我的博客: http://www.javacoder.cn/?p=546
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<bean id="trigger1" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="job"></property>
<property name="cronExpression" value="0 0/5 * * * ?"></property>
</bean>
<property name="jobDetail" ref="job"></property>
<property name="cronExpression" value="0 0/5 * * * ?"></property>
</bean>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询