1.jar包导入系统—这两个包
2.配置application.xml
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
<task:annotation-driven/>
<context:component-scan base-package="com.netmarch.*" />
3.使用dome
package com.netmarch.tjfx.util.controller;
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.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.netmarch.tjfx.qzjs.kcczkj.mapper.TjfxQzKcczkjMapper;
@Component
@Lazy(false)
@EnableScheduling
public class TestceshiController {
@Autowired
private TjfxQzKcczkjMapper kcczkjMapper;
@Scheduled(cron="0 0 0 1 1 ?")
public void outsystem(){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(dateFormat.format(new Date()));
kcczkjMapper.updatekcczkj();
kcczkjMapper.updatekcczkjfj();
}
}