views:

421

answers:

1

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.

+2  A: 

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().

skaffman
Thank you SKAFFMAN. It helped. :)
Walker
@Walker: An upvote and an answer acceptance is worth 25 thank you's...
skaffman