Home > OS >  How to get jobExecutionContext['key'] with class value key in xml file in spring batch
How to get jobExecutionContext['key'] with class value key in xml file in spring batch

Time:12-22

I can set lastJobExecutionId as jobExecutionContext['_lastJobExecutionId']. but the problem is _lastJobExecutionId is the value defined in another class. I don't want to use String '_lastJobExecutionId' in xml file and change it to reference of it (like x.y.z.CustomTasklet.KEY_LAST_JOB_EXECUTION_ID).

How do I fix it?

ASIS

    <bean id="reader"  scope="step">
        <property name="sqlSessionTemplate" ref="SqlSessionTemplate"/>
        <property name="queryId" value="mybatis.mapper.x.y.z.selectTarget"/>
        <property name="pageSize" value="1000"/>
        <property name="lastJobExecutionId" value="#{jobExecutionContext['_lastJobExecutionId']}"/>
    </bean>

want TOBE like...

    <bean id="reader"  scope="step">
        <property name="sqlSessionTemplate" ref="SqlSessionTemplate"/>
        <property name="queryId" value="mybatis.mapper.x.y.z.selectTarget"/>
        <property name="pageSize" value="1000"/>
        <property name="lastJobExecutionId" value="#{jobExecutionContext['x.y.z.CustomTasklet.KEY_LAST_JOB_EXECUTION_ID']}"/>
    </bean>

CodePudding user response:

This is more about SpEL syntax, you can refer to a type using the following notation:

<property name="lastJobExecutionId" value="#{jobExecutionContext[T(x.y.z.CustomTasklet).KEY_LAST_JOB_EXECUTION_ID]}"/>

Please check the reference documentation for more details about the syntax.

  • Related