Spring - How to load new hierarchical context?

Has anyone tried loading multiple hierarchical contexts (parent / child) with Spring?

Could you please explain how to do this as I couldn't find sufficient documentation on this?

Thanks in advance.

+2


source to share


3 answers


Spring's ContextLoaderListener and ContextLoader classes perform the task of initializing the webapp application context, and it is also optional to bind another application context to the parent.



In particular, the loadParentContext () method uses the ContextSingletonbeanFactoryLocator by default to try to find the parent context of the webapp, but if that doesn't fit, you can subclass the ContextLoader (and ContextLoaderListener) to programmatically find your apptext libraries.

+1


source


Looks like I figured out how to do this .. (thanks to " skaffman " for the help)

In web.xml, define the param context locatorFactorySelector

and set its value to the parent context of the beans.xml file. By default, the search is performed for the file pathpath *: beanRefContext.xml.



Here it is!

Now I need to see how to get my JUnits to load the parent context. Should be simple - just putting the file beanRefContext.xml

in the same directory, but looking.

+2


source


Create an app context with a third party app context as parent. This way the third party application context won't be able to see your beans, but your application context will be able to see the beans created by the third party library (it's the parent factory).

+1


source







All Articles