quartz任务调试

定义 applicationContext-timetask.xml 文件
----------------------
<?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: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-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<!-- 要调用的工作类 -->
<bean id="autoImportUserJob" class="cn.com.cheeyo.management.task.AutoImportUserJob" >
<property name="driver" value="${mq.dbdriver}" />
<property name="url" value="${mq.url}" />
<property name="userName" value="${mq.userName}" />
<property name="password" value="${mq.password}" />
</bean>

<!-- 定义调用对象和调用对象的方法 -->
<bean id="jobtask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类 -->
<property name="targetObject">
<ref bean="autoImportUserJob" />
</property>
<!-- 调用类中的方法 -->
<property name="targetMethod">
<value>work</value>
</property>
</bean>

<!-- 定义触发时间 -->
<bean id="autoImportUserTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="jobtask" />
</property>
<!-- cron表达式 此处定义为一直触发执行任务 -->
<property name="cronExpression">
<!--
<value> 0 0 0 25 3 ? * </value>
<value> 0 0/5 16 * * ? </value>
<value> 0 22 17 30 3 ? 2099 </value>
-->
<value>${autoImportUserTrigger.cronExpression}</value>
</property>
</bean>

<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="startQuertz" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="autoImportUserTrigger" />
<!-- 可继续加新的 -->
</list>
</property>
</bean>

</beans>

----------
server.properties中定义

mq.dbdriver=com.mysql.jdbc.Driver
mq.url=jdbc:mysql://localhost:3306/cheeyo
mq.userName=root
mq.password=123456
autoImportUserTrigger.cronExpression= 0 49 9 31 3 ? *

----------

具体代码见附件中文件.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于 Quartz 定时任务的 debug 调试,你可以按照以下几个步骤进行操作: 1. 确保 Quartz 配置文件正确:检查 Quartz 配置文件中的 job、trigger、scheduler 和相关属性是否正确配置,例如任务是否被正确加载、触发器是否被正确关联等。 2. 打印日志信息:在你的任务代码中添加日志输出,以便在运行时查看任务的执行情况。使用合适的日志框架,如 Log4j 或 SLF4J,并设置合适的日志级别来确保你能够看到足够的调试信息。 3. 手动触发任务:在调试过程中,可以手动触发任务来验证其执行情况。通过调用 Quartz 的 API 来触发任务,然后观察日志输出或其他相关的调试信息。 4. 使用调试工具:如果你的任务代码复杂或存在问题,可以使用调试工具来进行更深入的调试。例如,你可以使用断点来暂停任务的执行,以便逐步检查代码和变量的状态。 5. 检查异常信息:如果任务执行时出现异常,确保捕获并处理了所有可能的异常情况。查看异常信息并分析其原因,以便修复问题。 6. 检查依赖项:如果任务依赖于其他组件或服务,请确保这些依赖项都已正确配置和运行。例如,如果任务需要数据库连接,请确保数据库连接配置正确,并且数据库服务正常运行。 7. 单元测试:编写单元测试来验证任务的逻辑和执行结果。单元测试可以帮助你发现问题,并确保任务在不同情况下的预期行为。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值