[Java] [Tried] Spring Tutorial

less than 1 minute read

Summarize the learning in the spring tutorial

What I did

Task Schedule

##【environment】

  • Spring Tool Suite 4 :Version: 4.4.1.RELEASE
  • ProductName:Mac OS X
  • ProductVersion:10.14.6

[App to make]

Use Spring’s @Scheduled annotation and create an application that outputs the current time every 5 seconds

  • Move to the appropriate directory
$ git clone https://github.com/spring-guides/gs-scheduling-tasks.git
$ cd gs-scheduling-tasks
  • Edit: pom.xml -Add awaitility dependency (for testing cheduledTasksTest.java)

  • Create a scheduled task -Create: 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: 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, start app
$ /Users/#{myname}/projects/gs-scheduling-tasks/initial/target/scheduling-tasks-0.0.1-SNAPSHOT.jar


  • App launch -$ /Users/#{myname}/projects/gs-scheduling-tasks/initial/target/scheduling-tasks-0.0.1-SNAPSHOT.jar image.png

Reference article (Thank you always)


Task Schedule How to execute task periodically in Spring Boot