views:

258

answers:

1

I'm using org.springframework.web.servlet.DispatcherServlet and org.springframework.ws.transport.http.MessageDispatcherServlet in the same app but each is loading own application context, I need to load all beans in a single application context.

The application consists of typical layers web>app>dao etc

What I have tried is to use one single spring-root-context.xml by setting it in the contextConfigLocation.

But didn't help, this has been an issue for me for a long time an I would appreciate any help with this.

Any online references would be a great help.

+3  A: 

What you need here is the ContextLoaderListener. This is a ServletContextListener which creates a root WebApplicationContext that is shared amongst all servlets in that webapp.

Your DispatcherServlet and MessageDispatcherServlet will still create their own contexts, but each will have the root context as their parent, so they'll both be able to use beans defined in that root context, like DAOs etc. Some beans will have to remain in the servlets own contexts, such as controllers, view resolvers, SOAP endpoints, and so on, but the shared common beans can go in the root.

For an example on how to configure this, see the Spring docs.

skaffman
Hi skaffman, thanks to your good help its working like a dream now, thank you :)
Ramo
@Ramo: Glad to help. This is where you click the tick symbol next to my answer :)
skaffman