web.xml配置DispatcherServlet與ContextLoaderListener的問(wèn)題
請(qǐng)教一下老師,spring與springMVC整合在web.xml的配置有的會(huì)加上ContextLoaderListener,然后再有DispatcherServlet的配置,這兩者什么關(guān)系,為什么有的這樣配置?這個(gè)視頻中又只配置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
一開(kāi)始我也在疑問(wèn)為啥它沒(méi)有配置Spring的applicationcontext.xml那個(gè)配置文件,而選擇了在web.xml里面只聲明SpringMVC的配置文件,然后當(dāng)我把它整個(gè)項(xiàng)目都看了一遍之后,差不多了解個(gè)大概了,因?yàn)樗O(shè)置了自動(dòng)掃描bean,之后的一切都是通過(guò)注解,自動(dòng)注冊(cè)bean的,現(xiàn)在它不需要裝配Spring配置文件信息,自然也就不需要監(jiān)聽(tīng)器了