【发布时间】:2015-07-16 18:16:45
【问题描述】:
我想在以下代码/配置中的某处放置一个钩子,以便能够发现 JobInstanceAlreadyCompleteException,然后通过电子邮件向生产支持团队发送邮件告知发生了这种情况。
我在 Spring Batch 中尝试了 JobExecutionListener#beforeJob() 方法,但 JobInstanceAlreadyCompleteException 在作业执行之前发生。
我正在使用文档中的这个 Spring Batch Integration 配置:
<int:channel id="inboundFileChannel"/>
<int:channel id="outboundJobRequestChannel"/>
<int:channel id="jobLaunchReplyChannel"/>
<int-file:inbound-channel-adapter id="filePoller"
channel="inboundFileChannel"
directory="file:/tmp/myfiles/"
filename-pattern="*.csv">
<int:poller fixed-rate="1000"/>
</int-file:inbound-channel-adapter>
<int:transformer input-channel="inboundFileChannel"
output-channel="outboundJobRequestChannel">
<bean class="io.spring.sbi.FileMessageToJobRequest">
<property name="job" ref="personJob"/>
<property name="fileParameterName" value="input.file.name"/>
</bean>
</int:transformer>
我想处理JobInstanceAlreadyCompleteException,以防相同的 CSV 文件名作为作业参数出现。我要扩展org.springframework.integration.handler.LoggingHandler 吗?
我注意到该类正在报告错误:
ERROR org.springframework.integration.handler.LoggingHandler - org.springframework.messaging.MessageHandlingException: org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters={input.file.name=C:\Users\csv\file2015.csv}. If you want to run this job again, change the parameters.
【问题讨论】:
标签: spring-batch spring-integration