1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【やってみた】Spring チュートリアル

Last updated at Posted at 2020-08-08

springのチュートリアルでの学習をまとめる

##やったこと
タスクのスケジュール

##【環境】

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

【作るアプリ】

Spring の @Scheduledアノテーションを使用し、5秒ごとに現在時刻を出力するアプリを作成する

  • 適当なディレクトリに移動
$ git clone https://github.com/spring-guides/gs-scheduling-tasks.git
$ cd gs-scheduling-tasks
  • 編集:pom.xml

  • awaitility 依存関係の追加(cheduledTasksTest.java のテストのため)

  • スケジュールされたタスクを作成

  • 作成:新規ファイル (src/main/java/.../schedulingtasks/ScheduledTasks.java)

  • スケジューリングを有効にする

  • 編集:(src/main/.../schedulingtasks/SchedulingTasksApplication.java)

import org.springframework.scheduling.annotation.EnableScheduling;
  • 実行可能 JAR を構築する
  • 移動:mavenディレクトリに移動する
  • 実行1:「./mvnw spring-boot:run」 を使用してアプリケーションを実行する
  • 実行2:「./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] ------------------------------------------------------------------------

#実行、アプリ起動
$ /Users/#{myname}/projects/gs-scheduling-tasks/initial/target/scheduling-tasks-0.0.1-SNAPSHOT.jar


  • アプリ起動
  • $ /Users/#{myname}/projects/gs-scheduling-tasks/initial/target/scheduling-tasks-0.0.1-SNAPSHOT.jar
    image.png

参考記事(いつもありがとうございます)

タスクのスケジュール
Spring Bootでtaskを定期実行する方法

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?