在.net中作计划任务,就建立一个控制台项目能够了,可是在java里面不太同样,刚开始搞估计比较蒙圈。其实用springboot无论什么都是控制台程序。java
一、首先建立一springboot程序,而后在application上面打上注解:@EnableSchedulingspring
二、建立一个类,打上注解Component,其实主要就是能够加载到容器里面去。springboot
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()); } }