[XML] 纯文本查看 复制代码
<!--配置父级工程-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<!--配置WEB启动器 SpringMVC、Restful、jackson-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--配置springboot热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!--任务调度:quartz-->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
</dependency>
</dependencies>
<!--配置全局属性-->
<properties>
<!--配置jdk版本-->
<java.version>1.8</java.version>
</properties>
<!--配置maven插件-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
[Java] 纯文本查看 复制代码
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* Date:2018/7/22
* Author:FireDragon-WuJianHui
* Desc:设置项目
*/
@Component//组件
public class DemoOfQuartz {
//每一分钟执行一次
@Scheduled(cron = "0 0/1 * * * ?")
public void work() throws Exception{
System.out.println("在 "+new Date()+" 调用了work的方法");
}
//每5秒执行一次
@Scheduled(fixedRate = 5000)
public void eat() throws Exception{
System.out.println("在 "+new Date()+" 调用了eat的方法");
}
//每4秒执行一次
@Scheduled(cron = "0/4 * * * * ?")
public void sleep() throws Exception{
System.out.println("在 "+new Date()+" 调用了sleep的方法");
}
}
[Java] 纯文本查看 复制代码
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Date:2018/7/22
* Author:FireDragon-WuJianHui
* Desc:
*/
@SpringBootApplication
public class SpringBootStratApplication {
public static void main(String[] args){
//启动springboot程序
SpringApplication.run(SpringBootStratApplication.class);
}
}