Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the default WebApplicationContext?

I need the context to ApplicationContext.xml ,which I provided in web.xml as

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
 </listener> 

But I need a control for this in Controller class.

I tried many things including

WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();

but it doesnt help.

like image 203
Walker Avatar asked Mar 22 '10 21:03

Walker


1 Answers

Easiest solution is to use getWebApplicationContext() of WebApplicationContextUtils:

Find the root WebApplicationContext for this web application, which is typically loaded via ContextLoaderListener.

See also getRequiredWebApplicationContext().

like image 188
skaffman Avatar answered Sep 20 '22 14:09

skaffman