I have a web-application which is dependent on two other modules.
For simplicity let's call them ServiceA
module and ServiceB
module.
Each of these modules has various different dependencies and also a common dependency on the Entities
module.
Each of the above mentioned modules declares its own spring context file with information pertaining to its scope.
I'm trying now to decide how to "wire" these configuration files between the projects and I'm a bit stumped.
I know one option is just to declare all the "end" files (i.e. ServiceA, ServiceB and Entities) in the web.xml of the web-app (in the contextConfigLocation
param) but I don't like that option particularly since my actual use-case is more complex and has more internal dependencies which are shared.
My original intent was to declare in the contextConfigLocation
param only the config files for ServiceA
and ServiceB
since these are the only projects which the web-app is directly dependent upon (this is easy to see by looking at the maven pom), and then have both ServiceA
and ServiceB
to include this directive in their spring context configuration file <import resource="classpath:EntitiesContext.xml">
. The advantage with this approach is that it is consistent with the maven transitive approach where I declare what I'm dependent upon and if that module is dependent upon something it will drag it along with it. The problem with this approach is that I read here that all the beans in the Entities
module will be created twice (although only one instance will remain at the end) which is an expensive and unneeded action.
I'd like very much to hear how people solve this use-case since I don't think I've hit any corner case.
Thanks
Update
The syntax I ended up using was classpath*:META-INF/*/*Context.xml
since there are some issues with the syntax Thomasz suggested.
For additional reading see the bug report of spring (which partially resolved the issue) and a blog post regarding the issue