web.xml配置DispatcherServlet與ContextLoaderListener的問題
請教一下老師,spring與springMVC整合在web.xml的配置有的會加上ContextLoaderListener,然后再有DispatcherServlet的配置,這兩者什么關系,為什么有的這樣配置?這個視頻中又只配置DispatcherServlet
<listener>
? ? ? ? <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
下面是網(wǎng)上的回答解析:
http://stackoverflow.com/questions/11815339/role-purpose-of-contextloaderlistener-in-spring
http://syntx.io/difference-between-loading-context-via-dispatcherservlet-and-contextloaderlistener/
http://www.codesenior.com/en/tutorial/Spring-ContextLoaderListener-And-DispatcherServlet-Concepts
2017-03-28
一開始我也在疑問為啥它沒有配置Spring的applicationcontext.xml那個配置文件,而選擇了在web.xml里面只聲明SpringMVC的配置文件,然后當我把它整個項目都看了一遍之后,差不多了解個大概了,因為它設置了自動掃描bean,之后的一切都是通過注解,自動注冊bean的,現(xiàn)在它不需要裝配Spring配置文件信息,自然也就不需要監(jiān)聽器了