引入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定时任务集成


相关文章:

  • 2021-05-06
  • 2021-11-19
  • 2021-05-16
  • 2020-03-24
  • 2021-07-20
  • 2021-06-24
猜你喜欢
  • 2021-05-14
  • 2021-05-30
  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2021-05-01
相关资源
相似解决方案