Struts 1.1+ PlugIn that loads a Spring application context for the Struts
ActionServlet. This context will automatically refer to the root
WebApplicationContext (loaded by ContextLoaderListener/Servlet) as parent.
The default namespace of the WebApplicationContext is the name of the
Struts ActionServlet, suffixed with "-servlet" (e.g. "action-servlet").
The default location of the XmlWebApplicationContext configuration file
is therefore "/WEB-INF/action-servlet.xml".
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"/>
The location of the context configuration files can be customized
through the "contextConfigLocation" setting, analogous to the root
WebApplicationContext and FrameworkServlet contexts.
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/action-servlet.xml /WEB-INF/myContext.xml"/>
</plug-in>
Beans defined in the ContextLoaderPlugIn context can be accessed
from conventional Struts Actions, via fetching the WebApplicationContext
reference from the ServletContext. ActionSupport and DispatchActionSupport
are pre-built convenience classes that provide easy access to the context.
It is normally preferable to access Spring's root WebApplicationContext
in such scenarios, though: A shared middle tier should be defined there
rather than in a ContextLoaderPlugin context, for access by any web component.
ActionSupport and DispatchActionSupport autodetect the root context too.
A special usage of this PlugIn is to define Struts Actions themselves
as beans, typically wiring them with middle tier components defined in the
root context. Such Actions will then be delegated to by proxy definitions
in the Struts configuration, using the DelegatingActionProxy class or
the DelegatingRequestProcessor.
Note that you can use a single ContextLoaderPlugIn for all Struts modules.
That context can in turn be loaded from multiple XML files, for example split
according to Struts modules. Alternatively, define one ContextLoaderPlugIn per
Struts module, specifying appropriate "contextConfigLocation" parameters.
Note: The idea of delegating to Spring-managed Struts Actions originated in
Don Brown's Spring Struts Plugin.
ContextLoaderPlugIn and DelegatingActionProxy constitute a clean-room
implementation of the same idea, essentially superseding the original plugin.
Many thanks to Don Brown and Matt Raible for the original work and for the
agreement to reimplement the idea in Spring proper!
author: Juergen Hoeller since: 1.0.1 See Also: ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX See Also: ActionSupport See Also: DispatchActionSupport See Also: DelegatingActionProxy See Also: DelegatingRequestProcessor See Also: DelegatingTilesRequestProcessor See Also: org.springframework.web.context.ContextLoaderListener See Also: org.springframework.web.context.ContextLoaderServlet See Also: org.springframework.web.servlet.FrameworkServlet |