博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring定时任务配置
阅读量:4072 次
发布时间:2019-05-25

本文共 1261 字,大约阅读时间需要 4 分钟。

<!-- 配置定时器加载的目标类 -->
<bean id="quartzJob" class="com.rd.quartz.QuartzJob"></bean> 

<!-- 配置定时器详情 -->

<bean id="updateOrderStatusDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
   <property name="targetObject">
       <ref bean="quartzJob"/> <!-- 指定任务类 -->
   </property>
   <property name="targetMethod">
       <value>updateOrderStatus</value> <!-- 指定任务方法 -->
   </property>

</bean>

<!-- 配置定时器时间间隔 -->
<bean id="updateOrderStatusTimer" class="com.rd.quartz.InitializingCronTrigger">
   <property name="jobDetail">
       <ref bean="updateOrderStatusDetail"/>
   </property>
   <property name="cronExpression">
       <value>0 0/1 * * * ?</value><!-- 0分开始 每分钟执行一次-->
   </property> 
</bean>
       
<!-- 配置启动定时器 -->
<bean id="startQuertz" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
   <property name="triggers">
    <list>
<!-- 必需 -->
<ref bean="updateOrderStatusTimer" />
    </list>
   </property>

</bean>

在web.xml中配置定时器配置文件地址和类加载监听器

<!-- 配置Spring容器 -->

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
classpath:/spring/applicationQuartz.xml
    </param-value>
  </context-param>
<!-- 配置Spring启动监听器 -->
  <listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>

转载地址:http://fhmji.baihongyu.com/

你可能感兴趣的文章
星环后台研发实习面经
查看>>
大数相乘不能用自带大数类型
查看>>
字节跳动后端开发一面
查看>>
CentOS Tensorflow 基础环境配置
查看>>
centOS7安装FTP
查看>>
FTP的命令
查看>>
CentOS操作系统下安装yum的方法
查看>>
ping 报name or service not known
查看>>
FTP 常见问题
查看>>
zookeeper单机集群安装
查看>>
do_generic_file_read()函数
查看>>
Python学习笔记之数据类型
查看>>
Python学习笔记之特点
查看>>
Python学习笔记之安装
查看>>
shell 快捷键
查看>>
VIM滚屏操作
查看>>
EMC 2014存储布局及十大新技术要点
查看>>
linux内核内存管理(zone_dma zone_normal zone_highmem)
查看>>
将file文件内容转成字符串
查看>>
循环队列---数据结构和算法
查看>>