|
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);
> }
>
|
|
From: Juergen H. <ju...@in...> - 2005-10-03 09:27:40
|
Let me clarify the intentions here: DelegatingActionUtils's
getRequiredWebApplicationContext method *deliberately* only looks for the
ContextLoaderPlugIn-loaded context, as its intent is to look for Struts
Action bean definitions. Such Action beans don't belong in the root
application context but rather only in the Struts-specific
ContextLoaderPlugIn context.
As an aside: If you have both a root application context and a
ContextLoaderPlugIn context, the latter will automatically be a child of the
former and thus see all beans defined there. As a consequence, you can
easily pass service layer references (from the root context) into bean
properties of your Struts Action beans (defined in the ContextLoaderPlugIn
context).
I guess what you want to achieve is something different: You seem to use
DelegationActionUtils directly to fetch a reference to the Spring
WebApplicationContext, for custom bean access (that is, not for delegating
to Struts Action bean definitions). This is similar to what our
*ActionSupport classes do in their initWebApplicationContext implementation.
Hence, I've added a findRequiredWebApplicationContext method to
DelegatingActionUtils: first checking the Struts-specific context (loaded by
ContextLoaderPlugIn), then falling back to the root context (loaded by
ContextLoaderListener). That method is essentially factored out from
*ActionSupport but can also be used directly.
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...] On Behalf Of
Velorider
Sent: Saturday, October 01, 2005 10:14 AM
To: spr...@li....
Subject: [Springframework-developer] DelegatingActionUtils for STRUTS
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);
> }
>
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|