LoginSignup
16
18

More than 5 years have passed since last update.

Spring Batch:バッチ実行時の各種プレースホルダ

Last updated at Posted at 2014-05-07

Spring Batchでは、バッチ実行時の各フェーズで使用できるプレースホルダがある。bean定義で設定することも、@Valueのアノテーションを使用して取得することも可能。

注意点

使用したいbean定義のスコープをSpringBatch拡張の step にする

使用できるプレースホルダ

記法 説明
#{stepExecutionContext[name]} StepExectutionContextにセットされた値を参照する。主にStepListenerで値は設定される。Step内でのみ有効な値。
#{jobExecutionContext[name]} JobExecutionContextにセットされた値を参照する。Jobを通じてStepをまたいで参照可能。JobExecutionContextはStepExectutionContextから参照可能。
#{jobParameters[name]} SpringBatch実行時に引数として渡された値を参照。

設定例

 <bean id="..." class="..." scope="step">
        <property name="parent" ref="#{stepExecutionContext[helper]}" />
 </bean>

 <bean id="..." class="..." scope="step">
        <property name="name" value="#{stepExecutionContext['input.name']}" />
 </bean>

 <bean id="..." class="..." scope="step">
        <property name="name" value="#{jobParameters[input]}" />
 </bean>

 <bean id="..." class="..." scope="step">
        <property name="name" value="#{jobExecutionContext['input.stem']}.txt" />
 </bean>

@Value使用例

    @Value("#{jobParameters['userId']}")
    public void setUserId(String userId) {
        this.userId = userId;
    }

@Valueを使うときは、context:annotation-config を忘れずに。

参考

16
18
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
16
18