Spring整合配置:SpringSSM + task定时任务集成

引入jar包

Spring整合配置:SpringSSM + task定时任务集成

beans.xml中配置task

Spring整合配置:SpringSSM + task定时任务集成

测试类代码

package com.energy.ims.job;
import java.text.SimpleDateFormat;  
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


import com.energy.ims.service.CreateService;


  
@Component
@Lazy(value=false)
public class HelloJob2 {

@Autowired
private CreateService createService;
  
    public HelloJob2() {  
        System.out.println("HelloJob创建成功");  
    }  
    @Scheduled(cron = "5,15,25,35,45,55 * * * * ? ")  
    public void run() {  
        System.out.println("Hello MyJob33333  " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ").format(new Date()));
        createService.test();
    }
    @Scheduled(cron = "5,10,25,35,45,55 * * * * ? ")  
    public void run1() {  
    System.out.println("Hello MyJob2222222222222  " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ").format(new Date()));
    createService.test();
    }

}

web.xml中监听beans.xml

Spring整合配置:SpringSSM + task定时任务集成

以上完成,输出

Spring整合配置:SpringSSM + task定时任务集成