[英]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>
Why does the above give me the following error: 为什么上面的给我以下错误:
java.lang.IllegalStateException: No context available while replacing placeholders.
What would be the best way to work around this issue? 解决此问题的最佳方法是什么?
I believe the issue is that you wanted a step listener, and not a job listener. 我认为问题在于您需要一个逐步侦听器,而不是一个作业侦听器。 The step scope is out of scope where you've defined your listener, so scope step is unavailable - if it was a job listener, you wouldn't need the placeholders because you could obtain the variables from the current JobExecution. 步骤作用域超出了定义侦听器的范围,因此作用域步骤不可用-如果它是作业侦听器,则不需要占位符,因为您可以从当前JobExecution获取变量。
If you instead altered your configuration like so (assuming this is a step listener and not a job listener): 如果您改为这样更改配置(假设这是一个步骤侦听器,而不是作业侦听器):
<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>
I believe that would give you a proper step listener for the "step1" step - similar configuration if you wanted a listener for the second step. 我相信这将为“ step1”步骤提供适当的步骤侦听器-如果您希望第二步使用侦听器,则可以进行类似的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.