Reputation: 32061
I have 3 application contexts:
Spring managed creating a parent-child relationship for the latter two contexts.
Now I would like to add a simple global properties service to the first context and have it visible to the others (I could add it to applicationContext, but I may use it elsewhere outside the webapp context later and want to plan for that).
Since I didn't manage creation of the other two contexts (they were created by the dispatcher servlet and spring security which were launched from web.xml) I'm not clear how and where I should access them to define the first as the parent (well, only applicationContext should take the global context as its parent).
Upvotes: 2
Views: 767
Reputation: 403461
The parent-child relationship between (1) and (2) can be managed by the ContextLoaderListener
that you have in your web.xml
.
Specifically, have a look at the javadoc for ContextLoader.loadParentContext()
. This documents how the ContextLoaderListener
can locate context (1). It assumes that this global context was initialised via ContextSingletonBeanFactoryLocator
, which you may or may not have used to create that context.
If you did use ContextSingletonBeanFactoryLocator
, then it should be trivial, just follow the instructions in the javadoc. if you used some other way of bootstrapping the global context, then you can subclass ContextLoaderListener
, override the loadParentContext()
method to locate your global context, then use that in web.xml
instead of the standard ContextLoaderListener
.
Upvotes: 1