1

I am going to start a new Spring-Batch Project, need some Guidance in Structuring my Project. Few examples i could think of:

  1. Keep all Readers, Processors and Writers together.

    Reader -> Step 1, Step 2 Processor -> Step 1, Step 2 Writer -> Step 1, Step 2

  2. Divide into Steps and keep Reader, Processor and Writer together for each steps

    Step 1 -> Reader, Processor and Writer Step 2 -> Reader, Processor and Writer

Could you please suggest best possible structure?

2 Answers2

1

I recently did mine: enter image description here 1) Configuration at top contains general configuration for all the Jobs and so does the DataSource. 2) Runner is to run all the jobs. 3) SupplierReminder is the job that contain its own reader, mapper, configutaion, model, processor, scheduler and writer.

when you have other job create a new package which have similar structure as step 3

Akki
  • 73
  • 1
  • 11
  • Thanks Akki for your response, do you mean i should create new package for each job and its reader processor and writer i can keep it inside it? – Kunjal Neema Oct 20 '19 at 10:06
  • And what about when you will have multiple steps inside single job? are you keeping all readers of steps in one folder under Reader? – Kunjal Neema Oct 20 '19 at 10:07
  • Yes, for each job keep it in different package and everything regarding readers is in reader for that particular job. The jobs steps are kept in configuration of that job. You can add multiple steps in jobs like reader, processor and writer (you could configure retry etc also depending upon your requirement). – Akki Oct 21 '19 at 06:56
0

It depends on how you want to strucuture your system: by feature or by "layer".

There are no specific guidelines as it depends on the use case, but here are a couple of thoughts specific to (Spring) batch apps:

  • Readers/writers form a library of reusable components, so I would put them in separate packages and (re)use them in the steps that require them.
  • Listeners can fall in the same category as readers/writers too
  • Some steps can also be reused (commons tasklets like cleaning a directory or downloading a file) so steps can be seen as reusable components as well.

Finally jobs is where you need to figure out the best way to structure/package them (a jar per job, or multiple jobs in the same jar, etc).

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50