Spring Batchで
自動化
aosn読書会@湯涌温泉
2017/09/16
Takumi Okamoto
お前誰やねん
Name : 岡本 拓海
- Tasktoys Robotics 代表
- (株)BridgeSolution 取締役
普段は機械設計をしたり、Webのサーバーサイド書いたりして糊口をしのいでます。
SNSとか
- Twitter: @MrBearin
- Facebook: takumi.okamoto
Spring Batchとは何ぞや
- 仕事で使ったのでちょっと紹介
- JavaのフレームワークSpringFrameworkの一部
- リスタートや失敗時の復帰なども簡単に書ける
- 並列処理やWebインターフェース等、便利な機能が色々とある
概要 Job
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Stepの仕組み
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
やってみよう
- 普通にSpringApplicationを準備
- @EnableBatchConfigurationを付与したConfigurationクラスを準備
基本設定
基本はこのクラスの中に設定を書いてく
SpringBatchの基本構造
Job ⊃ Step ⊃ Tasklet or chunk
処理はどうやって書く?
- Taskletを実装する
- Reader/Writerを利用する <-こっちが多いかも
Taskletを実装する場合
値のやり取りがある場合
- Chunkを作る(BatchConfiguration.javaで)
- Reader / Processor / Writer を実装
Stepの設定
BatchConfiguration.javaで設定
Reader
DBから読込み等のデータ生成タスク
Processor
バッチ処理難関の本体になるクラスクラスを受け取って他のクラスへ変換
Writer
最終的な書き出し処理
DEMO
ソースはココを参照
その他
- Restを作ってAPI化できる
- マルチスレッド化も可能
使いどころは限られると思うけど、みんな使ってみてね!
# the End