英文:
Spring Batch : Remove stack trace of run time exception from exit description
问题
在我的Spring Batch作业中,如果在步骤ItemWriter中出现未处理的异常(例如,由于保存到数据库时出现了主键违规,导致数据不良),我的作业将失败,然后我会得到另一个错误,因为核心Spring Batch无法将失败的退出状态更新到BATCH_JOB_EXECUTION表中。原因是退出描述具有完整的堆栈跟踪,其大小大于数据库列的大小(2500)。
我应该如何在Spring Batch中处理这些异常?如何将此退出描述修剪为更小的自定义消息?
谢谢。
英文:
In my Spring Batch Job if there is an unhandled exception in step ItemWriter (for ex Primary Key Violation because of bad data while saving to DB), my job fails and then I get another error because core spring batch is not able to update the failed exit status to BATCH_JOB_EXECUTION table. The Reason Being that the exit Description has full stack trace which is larger than the size of db column (2500).
How should I handle these exceptions in spring batch? How can I trim this exit description to smaller custom message?
Thanks.
答案1
得分: 0
> 我应该如何在 Spring Batch 中处理这些异常?
我会通过在写入数据之前验证数据是否符合数据库架构(正确的类型、正确的长度等)来解决根本原因。数据验证 是项目处理器的典型用例。
> 我如何将此退出描述修剪为较小的自定义消息?
与其修剪堆栈跟踪(这会使其不可读,因此您将无法看到异常的根本原因,根本原因位于堆栈跟踪的末尾),您可以使用maxVarcharLength来增加列长度。
英文:
> How should I handle these exceptions in spring batch?
I would fix the root cause by validating data to be conform to the db schema (the right type, the right length, etc) before writing it. Data validation is a typical use case for an item processor.
> How can I trim this exit description to smaller custom message?
Instead of trimming the stack trace (this would make it unreadable and hence you will not be able to see the root cause of the exception which is at the end of the stack trace), you can enlarge the column length using maxVarcharLength.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论