Skip to content
Advertisement

Spring Batch : Remove stack trace of run time exception from exit description

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.

Advertisement

Answer

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.

Advertisement