0
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 1 year has passed since last update.

Spring Batch メモ

Last updated at Posted at 2023-02-05

Spring Batch メモ

導入

Spring Batch を勉強したので、まとめがてらメモ

環境

OS: mac OS Ventura (ver. 13.1)
IDE: IntelliJ CE

Step モデル

Chunk

以下IFが用意されており、それに従い作成

  • ItemReader
  • ItemProcessor
  • ItemWriter

Tasklet

Chunkにはまらないものを作成する際に使用

Listner

主にログ出力で使用
それぞれの実行前後、エラー発生時に起動可能

Job/Step間の値渡し

ExecutionContext(実行結果などを保持するクラス)

JobExecutionContext - Step間渡し可能
StepExecutionContext - Step間渡し不可

  • メリット: パラメータ等がDBに保存される(後追い可能)
  • デメリット: 実装が煩雑

Scope

@JobScope@StepScopeを付与したクラスで受け渡し可能

  • メリット: 実装が容易
  • デメリット: パラメータ等がDBに保存されない

実行時パラメータの設定

実行の構成を編集

バリデーション

DefaultJobParametersValidator クラスを使用

  • setRequiredKeys(必須チェック)
    RunIdIncrementer を使用している場合は、run.idを指定する必要がある
  • setOptionalKeys(オプションチェック)
  • afterPropertiesSet(パラメータ名重複チェック)
    Configファイルに設定

任意チェック

JobParametersValidator を継承したクラスを作成

参考

Spring解体新書(バッチ編): 基礎から学べるSpring Batch

0
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
0
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?