@Deprecated public class ContextLoaderPlugIn extends Object implements org.apache.struts.action.PlugIn
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!
SERVLET_CONTEXT_PREFIX
,
ActionSupport
,
DispatchActionSupport
,
DelegatingActionProxy
,
DelegatingRequestProcessor
,
DelegatingTilesRequestProcessor
,
ContextLoaderListener
,
FrameworkServlet
Modifier and Type | Field and Description |
---|---|
static Class |
DEFAULT_CONTEXT_CLASS
Deprecated.
Default context class for ContextLoaderPlugIn.
|
static String |
DEFAULT_NAMESPACE_SUFFIX
Deprecated.
Suffix for WebApplicationContext namespaces.
|
protected Log |
logger
Deprecated.
|
static String |
SERVLET_CONTEXT_PREFIX
Deprecated.
Prefix for the ServletContext attribute for the WebApplicationContext.
|
Constructor and Description |
---|
ContextLoaderPlugIn()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
protected WebApplicationContext |
createWebApplicationContext(WebApplicationContext parent)
Deprecated.
Instantiate the WebApplicationContext for the ActionServlet, either a default
XmlWebApplicationContext or a custom context class if set.
|
void |
destroy()
Deprecated.
Close the WebApplicationContext of the ActionServlet.
|
org.apache.struts.action.ActionServlet |
getActionServlet()
Deprecated.
Return the Struts ActionServlet that this PlugIn is associated with.
|
Class |
getContextClass()
Deprecated.
Return the custom context class.
|
String |
getContextConfigLocation()
Deprecated.
Return the explicit context config location, if any.
|
org.apache.struts.config.ModuleConfig |
getModuleConfig()
Deprecated.
Return the Struts ModuleConfig that this PlugIn is associated with.
|
String |
getModulePrefix()
Deprecated.
Return the prefix of the ModuleConfig that this PlugIn is associated with.
|
String |
getNamespace()
Deprecated.
Return the namespace for the ActionServlet, falling back to default scheme if
no custom namespace was set: e.g.
|
ServletContext |
getServletContext()
Deprecated.
Return the ServletContext that this PlugIn is associated with.
|
String |
getServletContextAttributeName()
Deprecated.
Return the ServletContext attribute name for this PlugIn's WebApplicationContext.
|
String |
getServletName()
Deprecated.
Return the name of the ActionServlet that this PlugIn is associated with.
|
WebApplicationContext |
getWebApplicationContext()
Deprecated.
Return this PlugIn's WebApplicationContext.
|
void |
init(org.apache.struts.action.ActionServlet actionServlet,
org.apache.struts.config.ModuleConfig moduleConfig)
Deprecated.
Create the ActionServlet's WebApplicationContext.
|
protected WebApplicationContext |
initWebApplicationContext()
Deprecated.
Initialize and publish the WebApplicationContext for the ActionServlet.
|
protected void |
onInit()
Deprecated.
Callback for custom initialization after the context has been set up.
|
void |
setContextClass(Class contextClass)
Deprecated.
Set a custom context class.
|
void |
setContextClassName(String contextClassName)
Deprecated.
Set a custom context class by name.
|
void |
setContextConfigLocation(String contextConfigLocation)
Deprecated.
Set the context config location explicitly, instead of relying on the default
location built from the namespace.
|
void |
setNamespace(String namespace)
Deprecated.
Set a custom namespace for the ActionServlet,
to be used for building a default context config location.
|
public static final String DEFAULT_NAMESPACE_SUFFIX
public static final Class DEFAULT_CONTEXT_CLASS
XmlWebApplicationContext
public static final String SERVLET_CONTEXT_PREFIX
protected final Log logger
public void setContextClassName(String contextClassName) throws ClassNotFoundException
public void setContextClass(Class contextClass)
public Class getContextClass()
public void setNamespace(String namespace)
public String getNamespace()
public void setContextConfigLocation(String contextConfigLocation)
public String getContextConfigLocation()
public final void init(org.apache.struts.action.ActionServlet actionServlet, org.apache.struts.config.ModuleConfig moduleConfig) throws ServletException
init
in interface org.apache.struts.action.PlugIn
ServletException
public final org.apache.struts.action.ActionServlet getActionServlet()
public final String getServletName()
public final ServletContext getServletContext()
public final org.apache.struts.config.ModuleConfig getModuleConfig()
public final String getModulePrefix()
ModuleConfig.getPrefix()
protected WebApplicationContext initWebApplicationContext() throws BeansException, IllegalStateException
Delegates to createWebApplicationContext(org.springframework.web.context.WebApplicationContext)
for actual creation.
Can be overridden in subclasses. Call getActionServlet()
and/or getModuleConfig()
to access the Struts configuration
that this PlugIn is associated with.
BeansException
- if the context couldn't be initializedIllegalStateException
- if there is already a context for the Struts ActionServletgetActionServlet()
,
getServletName()
,
getServletContext()
,
getModuleConfig()
,
getModulePrefix()
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) throws BeansException
This implementation expects custom contexts to implement ConfigurableWebApplicationContext. Can be overridden in subclasses.
BeansException
- if the context couldn't be initializedsetContextClass(java.lang.Class)
,
XmlWebApplicationContext
public String getServletContextAttributeName()
The default implementation returns SERVLET_CONTEXT_PREFIX + module prefix.
SERVLET_CONTEXT_PREFIX
,
getModulePrefix()
public final WebApplicationContext getWebApplicationContext()
protected void onInit() throws ServletException
ServletException
- if initialization failedpublic void destroy()
destroy
in interface org.apache.struts.action.PlugIn
ConfigurableApplicationContext.close()