Class PortletApplicationContextUtils
- java.lang.Object
- org.springframework.web.portlet.context.PortletApplicationContextUtils
public abstract class PortletApplicationContextUtils extends Object
Convenience methods for retrieving the rootWebApplicationContext
for a givenPortletContext
. This is useful for programmatically accessing a Spring application context from within custom Portlet implementations.- Since:
- 2.0
- Author:
- Juergen Hoeller, John A. Lewis
- See Also:
ContextLoader
,WebApplicationContextUtils
,FrameworkPortlet
,DispatcherPortlet
Constructor Summary
Constructors Constructor Description PortletApplicationContextUtils()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ApplicationContext
getRequiredWebApplicationContext(PortletContext pc)
Find the rootWebApplicationContext
for this web app, typically loaded viaContextLoaderListener
.static ApplicationContext
getWebApplicationContext(PortletContext pc)
Find the rootWebApplicationContext
for this web app, typically loaded viaContextLoaderListener
.static void
initPortletPropertySources(MutablePropertySources propertySources, ServletContext servletContext, PortletContext portletContext, PortletConfig portletConfig)
ReplaceServlet
- andPortlet
-basedstub property sources
with actual instances populated with the givenservletContext
,portletContext
andportletConfig
objects.
Constructor Detail
PortletApplicationContextUtils
public PortletApplicationContextUtils()
Method Detail
getWebApplicationContext
public static ApplicationContext getWebApplicationContext(PortletContext pc)
Find the rootWebApplicationContext
for this web app, typically loaded viaContextLoaderListener
.Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.
- Parameters:
pc
- PortletContext to find the web application context for- Returns:
- the root WebApplicationContext for this web app, or
null
if none (typed to ApplicationContext to avoid a Servlet API dependency; can usually be casted to WebApplicationContext, but there shouldn't be a need to) - See Also:
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
getRequiredWebApplicationContext
public static ApplicationContext getRequiredWebApplicationContext(PortletContext pc) throws IllegalStateException
Find the rootWebApplicationContext
for this web app, typically loaded viaContextLoaderListener
.Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.
- Parameters:
pc
- PortletContext to find the web application context for- Returns:
- the root WebApplicationContext for this web app (typed to ApplicationContext to avoid a Servlet API dependency; can usually be casted to WebApplicationContext, but there shouldn't be a need to)
- Throws:
IllegalStateException
- if the root WebApplicationContext could not be found- See Also:
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
initPortletPropertySources
public static void initPortletPropertySources(MutablePropertySources propertySources, ServletContext servletContext, PortletContext portletContext, PortletConfig portletConfig)
ReplaceServlet
- andPortlet
-basedstub property sources
with actual instances populated with the givenservletContext
,portletContext
andportletConfig
objects.This method is idempotent with respect to the fact it may be called any number of times but will perform replacement of stub property sources with their corresponding actual property sources once and only once.
- Parameters:
propertySources
- theMutablePropertySources
to initialize (must not benull
)servletContext
- the currentServletContext
(ignored ifnull
or if theservlet context property source
has already been initialized)portletContext
- the currentPortletContext
(ignored ifnull
or if theportlet context property source
has already been initialized)portletConfig
- the currentPortletConfig
(ignored ifnull
or if theportlet config property source
has already been initialized)- See Also:
PropertySource.StubPropertySource
,WebApplicationContextUtils.initServletPropertySources(MutablePropertySources, ServletContext)
,ConfigurableEnvironment.getPropertySources()