spring-framework / org.springframework.web.context.support / WebApplicationContextUtils / findWebApplicationContext

findWebApplicationContext

@Nullable open static fun findWebApplicationContext(sc: ServletContext): WebApplicationContext

Find a unique WebApplicationContext for this web app: either the root web app context (preferred) or a unique WebApplicationContext among the registered ServletContext attributes (typically coming from a single DispatcherServlet in the current web application).

Note that DispatcherServlet's exposure of its context can be controlled through its publishContext property, which is true by default but can be selectively switched to only publish a single context despite multiple DispatcherServlet registrations in the web app.

Parameters

sc - ServletContext to find the web application context for

Return
the desired WebApplicationContext for this web app, or null if none

Since
4.2

See Also
#getWebApplicationContext(ServletContext)ServletContext#getAttributeNames()