vendredi 27 mai 2016

Is it best practice to design Spring Application in such a way that we need to create same context multiple times?

I am going to start a new project using Spring framework. As I dont have much experience in Spring I need your help to sort out few confusions.

Lets look at use case

My application uses Spring integration framework. The core functionality of my app is,

  1. I need to poll multiple directories from file system,
  2. read the files(csv mostly),
  3. process some operations on them and insert them to database.

Currently I have set up spring integration flow for it. Which has inbound-chaneell-adapter for polling and then file traverse through the channels and at the end inserted into database.

My concerns are

  1. Number of directories application supposed to poll will be decided at runtime. Hence I need to create inbound-chanell-adapter at runtime (as one chanell adapter can poll only one directory at once) and cant define them statically in my spring context xml (As I dont know the how many I need).

  2. Each directory has certain properties which should be applied to the file while processing.(While going through the integration flow)

  3. So right now what I am doing is I am loading new ClassPathXmlApplicationContext("/applicationContext.xml"); for each directory. And cache the required properties in that newly created context. And use them at the time of processing (in <int:service-activator>).

Drawbacks of current design

  1. Separate context is created for each directory.
  2. Unnecessary beans are duplicated. (Database session factories and like)

So is there any way to design the application in such a way that context will not be duplicated. And still I can use properties of each directory throughout the integration flow at the same time???

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire