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

getWebApplicationContext

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

Find the root WebApplicationContext for this web app, typically loaded via org.springframework.web.context.ContextLoaderListener.

Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.

Parameters

sc - ServletContext to find the web application context for

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

See Also
org.springframework.web.context.WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE

@Nullable open static fun getWebApplicationContext(sc: ServletContext, attrName: String): WebApplicationContext

Find a custom WebApplicationContext for this web app.

Parameters

sc - ServletContext to find the web application context for

attrName - the name of the ServletContext attribute to look for

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