Spring+Quartz 定时任务

1、spring-quartz.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:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">

    
    <bean id="workJob" class="Test.FinishWorkTask">bean>

    
    <bean id="workTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        
        <property name="targetObject" ref="workJob">property>
        
        <property name="targetMethod" value="finish">property>
        
        <property name="concurrent" value="false">property>
    bean>

    
    <bean id="workTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="workTask">property>
        
        <property name="cronExpression" value="0/3 * * * * ?">property>
    bean>

    
    <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="workTrigger"/>
            list>
        property>
    bean>
beans>

2、FinishWorkTask .java

package Test;

public class FinishWorkTask {
    public void finish() {
        System.out.println( "finish。。。" );
    }
}

你可能感兴趣的:(Spring+Quartz 定时任务)