how to create a report on filtered items in spring-batch?

佐手、 提交于 2019-12-05 14:26:32

The best way to approach this would be to raise exceptions from within your ItemProcessor(s) and filter those as skip exceptions. Then use a SkipListener to write them to another output. Place your detailed message in the message for the exception so you can include it in your output. Setting the skip limit to something extremely high such as 999999 will prevent your job from failing due to the number of skips.

I have done this very successfully on quite a few spring-batch jobs and it's not an uncommon pattern.

Let me know if you have further questions!

I'm facing a similar situation, and the approach that I've decided to use is inspired by the null object pattern. I filter unwanted items as usual by returning null. If I find an item that I want to still be written, but differently, I return a non-null, but one with a specific state that would be impossible to enter during normal execution. When my writer sees this, it knows to handle it differently. If required, the null-state could be designed to give the writer information about how to interpret it.

This has some pretty obvious drawbacks, but I think the biggest benefit is that it allows you to keep the complexity of your usage of spring's framework down to a minimum.

Also, the fact that you have access to what sounds like plaintext usernames and passwords worries me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!