Home » Uncategorized » Get Spring Dispatcher servlet Spring context from ServletContext

Get Spring Dispatcher servlet Spring context from ServletContext

Noting down a trick which I keep forgetting – in order to be able to look it up in a future.
The way to get Spring’s Dispatcher servlet Spring context from webapp’s ServletContext.

WebApplicationContextUtils.getWebApplicationContext(servletContext, FrameworkServlet.SERVLET_CONTEXT_PREFIX + "dispatcher")

Where “dispatcher” is the name of the servlet as configured in web.xml (i.e. <servlet-name>dispatcher</servlet-name>).

P.S. More info on the subject can be found here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s