ContextLoadListener and DispatcherServlet

天大地大妈咪最大 提交于 2019-12-08 07:19:18

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/3234544/contextloadlistener-and-dispatcherservlet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!