Summarize the learning in the spring tutorial
Create an app that outputs the current time every 5 seconds using Spring's @Scheduled
annotation
--Move to a suitable directory
$ git clone https://github.com/spring-guides/gs-scheduling-tasks.git
$ cd gs-scheduling-tasks
--Edit: pom.xml --add awaitility dependency (for testing scheduledTasksTest.java)
--Create a scheduled task --Created: New file (src / main / java /.../ schedulingtasks/ScheduledTasks.java)
--Enable scheduling --Edit: (src / main /.../ schedulingtasks/SchedulingTasksApplication.java)
import org.springframework.scheduling.annotation.EnableScheduling;
--Build an executable JAR --Move: Move to maven directory --Run 1: Run the application using "./mvnw spring-boot: run" --Execution 2: Copy and paste the path displayed in the log after "./mvnw clean package".
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ scheduling-tasks ---
[INFO] Building jar: /Users/#{myname}/projects/gs-scheduling-tasks/initial/target/scheduling-tasks-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.3.2.RELEASE:repackage (repackage) @ scheduling-tasks ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.307 s
[INFO] Finished at: 2020-08-08T21:52:43+09:00
[INFO] ------------------------------------------------------------------------
#Run, launch app
$ /Users/#{myname}/projects/gs-scheduling-tasks/initial/target/scheduling-tasks-0.0.1-SNAPSHOT.jar
--App launch
Task Schedule How to periodically execute tasks in Spring Boot
Recommended Posts