在.net中做计划任务,就创建一个控制台项目可以了,但是在java里面不太一样,刚开始搞估计比较蒙圈。其实用springboot不管什么都是控制台程序。
1、首先创建一springboot程序,然后在application上面打上注解:@EnableScheduling
2、创建一个类,打上注解@Component,其实主要就是可以加载到容器里面去。
package com.example.console;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
public class HomeConsole {
@Scheduled(cron = "0/10 * * * * *")
public void home() {
System.out.println("测试效果" + new Date().toString());
}
}