mirror of
https://github.com/ityouknow/spring-boot-examples.git
synced 2026-03-13 10:22:11 +08:00
add spring-boot-scheduler
This commit is contained in:
@@ -33,8 +33,8 @@ Spring Boot 使用的各种示例,以最简单、最实用为标准,此开
|
||||
- [spring-boot-thymeleaf](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-thymeleaf):Spring Boot 3.0 Thymeleaf 语法、布局使用示例
|
||||
- [spring-boot-jpa](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-jpa):Spring Boot 3.0 Jpa 操作、多数据源使用示例
|
||||
- [spring-boot-mybatis](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-mybatis):Spring Boot 3.0 Mybatis 注解、xml 使用、多数据源使用示例
|
||||
- [spring-boot-rabbitmq](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-rabbitmq):Spring Boot 3.0 RabbitMQ 各种常见场景使用示例
|
||||
|
||||
- [spring-boot-rabbitmq](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-rabbitmq):Spring Boot 3.0 RabbitMQ 各种常见场景使用示例
|
||||
- [spring-boot-scheduler](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-scheduler):Spring Boot 3.0 定时任务 scheduler 使用示例
|
||||
---
|
||||
|
||||
> 如果大家想了解关于 Spring Boot 的其它方面应用,也可以以[issues](https://github.com/ityouknow/spring-boot-examples/issues)的形式反馈给我,我后续来完善。
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
spring.application.name=spring-boot-rabbitmq
|
||||
|
||||
spring.rabbitmq.host=119.91.142.6
|
||||
spring.rabbitmq.host=192.0.0.6
|
||||
spring.rabbitmq.port=5672
|
||||
spring.rabbitmq.username=admin
|
||||
spring.rabbitmq.password=admin
|
||||
|
||||
58
spring-boot-scheduler/pom.xml
Normal file
58
spring-boot-scheduler/pom.xml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.neo</groupId>
|
||||
<artifactId>spring-boot-scheduler</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>spring-boot-scheduler</name>
|
||||
<description>Demo project for Spring Boot and scheduler</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.neo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class SchedulerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SchedulerApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.neo.task;
|
||||
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by summer on 2016/12/1.
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class Scheduler2Task {
|
||||
|
||||
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
@Scheduled(fixedRate = 6000)
|
||||
public void reportCurrentTime() {
|
||||
System.out.println("现在时间:" + dateFormat.format(new Date()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.neo.task;
|
||||
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by summer on 2016/12/1.
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class SchedulerTask {
|
||||
|
||||
private int count=0;
|
||||
|
||||
@Scheduled(cron="*/6 * * * * ?")
|
||||
private void process(){
|
||||
System.out.println("this is scheduler task runing "+(count++));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
spring.application.name=spirng-boot-scheduler
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.neo;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SchedulerApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
System.out.println("hello world");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user