开发者

How to make the 2 applicationContexts created in a Spring-MVC app children of a global applicationContext

I have 3 application contexts:

  • A global context which is responsible for launching Jetty servlet container, launched from main()
  • An applicationContext parent to each webapp in jetty (started by SpringSecurity
  • n xyz-servlet contexts for each webapp (I run 1 webapp)

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 conte开发者_如何学运维xt as its parent).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜