【问题标题】:如何在spring批处理的xml文件中使用类值键获取jobExecutionContext ['key']
【发布时间】:2022-01-22 13:22:19
【问题描述】:

我可以将lastJobExecutionId 设置为jobExecutionContext['_lastJobExecutionId']。但问题是_lastJobExecutionId 是另一个类中定义的值。我不想在 xml 文件中使用 String '_lastJobExecutionId' 并将其更改为它的引用(如x.y.z.CustomTasklet.KEY_LAST_JOB_EXECUTION_ID)。

我该如何解决?

ASIS

    <bean id="reader" class="x.y.z.CustomReader" 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>

想要 TOBE 喜欢...

    <bean id="reader" class="x.y.z.CustomReader" 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>

【问题讨论】:

    标签: xml spring spring-batch


    【解决方案1】:

    这更多的是关于 SpEL 语法,您可以使用以下符号来引用类型:

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

    有关语法的更多详细信息,请查看reference documentation

    【讨论】:

    • 答案有效。谢谢!! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多