Spring定时任务实现

时间:2022-01-25 07:49:08
<?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:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-3.1.xsd" default-lazy-init="true">
<description>Spring Job定时器配置</description>

<!-- 定时任务 -->
<bean id="scheduleFactoryBean"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="dhhhl"/>
</list>
</property>
</bean>

<!--调用的Job配置-->
<bean id="dhhhl" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="dhhhlJob"></property>
<!-- 配置调用时间周期-->
<property name="cronExpression" value="0 09 15 * * ?"></property>
</bean>
<bean id="dhhhlJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<!--配置调用的类,该类继承QuartzJobBean -->
<property name="jobClass" value="com.myspringquartz.job.TestSyn"></property>
</bean>
</beans>


//定时任务配置执行的类
public class TestSyn extends QuartzJobBean
{
    
    private JobService jobservice;
    //构造函数中初始化调用的业务层
    public OrderMeetBenefitSyn(){
        jobservice=(JobService)SpringContextHolder.getApplicationContext().getBean("jobservice");
        
    }
    
    @Override
    //实际执行的定时任务实现
    protected void executeInternal(JobExecutionContext arg0)
        throws JobExecutionException
    {
      
    }
}