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 ? *

----------

具体代码见附件中文件.

你可能感兴趣的:(工作,mysql,xml,jdbc,quartz)