[英]Spring Batch: How do I use placeholders in step listeners?
<beans>
<batch:job id="job1" restartable="false">
<batch:step id="step1" next="step2">
<batch:tasklet>
<batch:chunk reader="readerA" writer="writerA" commit-interval="1" />
</batch:tasklet>
</batch:step>
<batch:step id="step2">
<batch:tasklet ref="tasklet1"/>
</batch:step>
<batch:listeners>
<batch:listener ref="listenerA" />
</batch:listeners>
</batch:job>
<bean id="listenerA" class="com.example.ListenerA" scope="step">
<property name="archiveDate" value="#{jobParameters['jobRunDate']}" />
</bean>
</beans>
为什么上面的给我以下错误:
java.lang.IllegalStateException: No context available while replacing placeholders.
解决此问题的最佳方法是什么?
我认为问题在于您需要一个逐步侦听器,而不是一个作业侦听器。 步骤作用域超出了定义侦听器的范围,因此作用域步骤不可用-如果它是作业侦听器,则不需要占位符,因为您可以从当前JobExecution获取变量。
如果您改为这样更改配置(假设这是一个步骤侦听器,而不是作业侦听器):
<batch:step id="step1" next="step2">
<batch:tasklet>
<batch:chunk reader="readerA" writer="writerA" commit-interval="1" />
<batch:listeners>
<batch:listener ref="listenerA" />
</batch:listeners>
</batch:tasklet>
</batch:step>
我相信这将为“ step1”步骤提供适当的步骤侦听器-如果您希望第二步使用侦听器,则可以进行类似的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.