Reputation: 1459
I am a bit familiar with Spring framework but am still having lots of question concerning use of spring from project architectural view point. Now I am setting up Spring 3 and a Maven web application and am willing to try out all the the fancy component-scan's and autowiring features however this is where I get confused.
I am trying to break the project into sub-modules. And at some point these sub-modules may include something-context.xml
in classpath*:resource/META-INF
, like for instance when I will want to define a datSource related stuff in a separate module. So that's fine spring let's you load context files from within class-paths of all of the jars.
But here is where it gets vague - say I am using component scan. I am obviously using spring DispatcherServlet
and it needs a servlet context to be loaded, and then there is a global application context parameter specified in web.xml contextConfigLocation
.
So now servlet context config has a component-scan feature enabled for com.mycom.project.controllers
and context loaded in the global contextConfigLocation
has a context loaded with component scan feature for package com.mycom.project
also searches for classpath*:META-INF/spring/*-context.xml
.
So my question is - does this load controller's twice given that component scan is used for a for com.mycom.project.controllers
and com.mycom.project
? Or is it all loaded into one huge container and the contextConfigLocation
parameter for either DispatcherServlet
or global declaration is sort of access issue ? As in DispatcherServlet
will reach only what's defined in servlet-context.xml
but won't be able to use anything else?
And if my assumption is wrong, could I have a suggestion on how to manage multi-module project issues?
Thanks.
Upvotes: 1
Views: 750
Reputation: 2625
Yes, you might run into trouble. See this link for how to solve your problem.
@Service are constructed twice
The way you proceed when creating modules seems valid to me. You have a context.xml file for each module and all will get loaded once you load the application. Your modules are self-contained and can also be used in different environments. That's pretty much the way I'd also do it.
Upvotes: 2