|
From: Velorider <vel...@pu...> - 2005-10-02 23:35:58
|
I ran across a problem when I tried to load the WebApplicationContext using
the ContextLoaderListener in a multi servlet, plus STRUTS environment. When
loading the WebApplicationContext with the ContextLoaderListener the web app
context is stored at
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE within the
servlet context. This prevents DelegatingActionUtils from finding the context
because it only expects the web app context to be loaded by the ContextPlugin
and stored at ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX.
This is fine if only running a STRUTS application. But larger applications
will include other servlets that require the web application context. Of
coarse they could locate the web app context by looking for
ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX but this seems strange since it
STRUS spefic. Plus this requires that the STRUTS action servlet load first so
the Context plugin can initialize the web context before the other servlets
use it.
My fix was to add a check for the web context at WebApplicationContext.
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE before throwing the exception and
after looking in ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX. This should
mentain backwards compatibility and allows the ContextLoaderListener to
initialize the web context for other servlet and still use Spring with
STRUTS.
Below is my patch for DelegatingActionUtils in 1.2.5. Does this seems like a
good solution and if so how can it be submited.
Thanks
John
68a69,73
> if (wac == null) {
> wac = (WebApplicationContext)
actionServlet.getServletContext().getAttribute(WebApplicationContext.
> ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
> }
>
|