I have a multi-module Maven project that uses Spring IoC, something like
parent-proj
- module1
- module2
- module3
- web-module
I question is:
What is the best practice to assemble applicationContext files? Should I create a gigantic applicationContext-web.xml in the web-module? Or should I create applicationContext-module<#>.xml in each sub-module, and import all of them in my applicationContext-web.xml?
I have been using the second option. Now it looks like things a bit out of control (e.g. beans override beans with the same id, etc).
Thanks.
First, if module1, module2 and module3 are purely java libraries (for instance, contains Domain Model, DAO, Service classes and etc) that are referenced and used in web-module, we usually don’t manipulate Spring container in this purely java libraries.
Second, you should not split Spring container by project module. Depend on the demand, you can spilt Spring container by application layer and define multiple applicationContext files in web-module project (to avoid single gigantic applicationContext.xml). For instance, this is what we usually do:
Hope that make sense.