tags:

views:

23

answers:

1

Is it ok to define both the ContextLoadListener and DispatcherServlet in the web.xml or are they mutually exclusive?

+3  A: 

No, they're not mutually exclusive.

ContextLoaderListener manages an appcontext which is associated with the whole webapp. DispatcherServlet manages a context associated with that specific servlet. The webapp context is the "parent" of the servlet appcontext, and all beans in the webapp appcontext are visible to beans in the servlet appcontext.

If you have only one servlet, there's not many reasons to use ContextLoaderListener. If you have multiple servlets, it's good to put the shared beans in the webbapp context where practical, so they can be reused.

skaffman