Reputation: 14222
Is it ok to define both the ContextLoadListener and DispatcherServlet in the web.xml or are they mutually exclusive?
Upvotes: 1
Views: 585
Reputation: 403501
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.
Upvotes: 6