|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.web.struts.ContextLoaderPlugIn
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 auto-detect 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.
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 standard Spring!
SERVLET_CONTEXT_ATTRIBUTE
,
ActionSupport
,
DispatchActionSupport
,
DelegatingActionProxy
,
DelegatingRequestProcessor
,
DelegatingTilesRequestProcessor
,
ContextLoaderListener
,
ContextLoaderServlet
,
FrameworkServlet
Field Summary | |
static java.lang.Class |
DEFAULT_CONTEXT_CLASS
Default context class for ContextLoaderPlugIn. |
static java.lang.String |
DEFAULT_NAMESPACE_SUFFIX
Suffix for WebApplicationContext namespaces. |
protected org.apache.commons.logging.Log |
logger
|
static java.lang.String |
SERVLET_CONTEXT_ATTRIBUTE
Name of the ServletContext attribute for the WebApplicationContext |
Constructor Summary | |
ContextLoaderPlugIn()
|
Method Summary | |
protected WebApplicationContext |
createWebApplicationContext(WebApplicationContext parent)
Instantiate the WebApplicationContext for the ActionServlet, either a default XmlWebApplicationContext or a custom context class if set. |
void |
destroy()
Close the WebApplicationContext of the ActionServlet. |
org.apache.struts.action.ActionServlet |
getActionServlet()
Return the ActionServlet that this PlugIn is associated with. |
java.lang.Class |
getContextClass()
Return the custom context class. |
java.lang.String |
getContextConfigLocation()
Return the explicit context config location, if any. |
java.lang.String |
getNamespace()
Return the namespace for the ActionServlet, falling back to default scheme if no custom namespace was set: e.g. |
WebApplicationContext |
getWebApplicationContext()
Return the ActionServlet's WebApplicationContext. |
void |
init(org.apache.struts.action.ActionServlet actionServlet,
org.apache.struts.config.ModuleConfig moduleConfig)
Create the ActionServlet's WebApplicationContext. |
protected WebApplicationContext |
initWebApplicationContext()
Initialize and publish the WebApplicationContext for the ActionServlet. |
protected void |
onInit()
Callback for custom initialization after the context has been set up. |
void |
setContextClass(java.lang.Class contextClass)
Set a custom context class. |
void |
setContextClassName(java.lang.String contextClassName)
Set a custom context class by name. |
void |
setContextConfigLocation(java.lang.String contextConfigLocation)
Set the context config location explicitly, instead of relying on the default location built from the namespace. |
void |
setNamespace(java.lang.String namespace)
Set a custom namespace for the ActionServlet, to be used for building a default context config location. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String DEFAULT_NAMESPACE_SUFFIX
public static final java.lang.Class DEFAULT_CONTEXT_CLASS
XmlWebApplicationContext
public static final java.lang.String SERVLET_CONTEXT_ATTRIBUTE
protected final org.apache.commons.logging.Log logger
Constructor Detail |
public ContextLoaderPlugIn()
Method Detail |
public void setContextClassName(java.lang.String contextClassName) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
createWebApplicationContext(org.springframework.web.context.WebApplicationContext)
public void setContextClass(java.lang.Class contextClass)
createWebApplicationContext(org.springframework.web.context.WebApplicationContext)
public java.lang.Class getContextClass()
public void setNamespace(java.lang.String namespace)
public java.lang.String getNamespace()
public void setContextConfigLocation(java.lang.String contextConfigLocation)
public java.lang.String getContextConfigLocation()
public final void init(org.apache.struts.action.ActionServlet actionServlet, org.apache.struts.config.ModuleConfig moduleConfig) throws javax.servlet.ServletException
init
in interface org.apache.struts.action.PlugIn
javax.servlet.ServletException
protected WebApplicationContext initWebApplicationContext() throws BeansException
BeansException
- if the context couldn't be initializedcreateWebApplicationContext(org.springframework.web.context.WebApplicationContext)
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) throws BeansException
BeansException
- if the context couldn't be initializedsetContextClass(java.lang.Class)
,
XmlWebApplicationContext
public final org.apache.struts.action.ActionServlet getActionServlet()
public final WebApplicationContext getWebApplicationContext()
protected void onInit() throws javax.servlet.ServletException
javax.servlet.ServletException
- if initialization failedpublic void destroy()
destroy
in interface org.apache.struts.action.PlugIn
ConfigurableApplicationContext.close()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |