I am new to Spring Batch. I have a simple job that includes reader, processor, writer and listeners.
Sample of a Step method code is below
@Bean public Step step1() { return stepBuilderFactory.get("step1") .<Person, Person> chunk(1) .reader(reader()).listener(customReadItemListener) .processor(processor()).listener(customProcessListener) .writer(writer()).listener(customWriteListener) taskExecutor(taskExecutor()) .build(); }
All Exceptions related to logic within Reader , Processor and Writer being handled by overwriting onReadError, onProcessError and onWriteError respectively. Inside of those methods I invoke my custom ExceptionService where I am handling exception and writing what I need to the log file.
However, I came across issue that I can not figure out yet. In my writer I am reading properties file to get output file name. Part of my error handling test is setting file name to non existing file and try to handle File Not found exception. Yet, when I am running my test I am not able to catch the exception in my customWriteListener. I have tried to add StepListener, ChunkListener, but neither one able to catch the exception and it is being throwing to the console. I understand that this is a System type of error and should be handled by Framework. My question what is the best approach to wrap it the same way I am handling business type of exception , by cathcing it and calling my ExceptionService?