请教一下老师,spring与springMVC整合在web.xml的配置有的会加上ContextLoaderListener,然后再有DispatcherServlet的配置,这两者什么关系,为什么有的这样配置?这个视频中又只配置DispatcherServlet
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
下面是网上的回答解析:
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
一开始我也在疑问为啥它没有配置Spring的applicationcontext.xml那个配置文件,而选择了在web.xml里面只声明SpringMVC的配置文件,然后当我把它整个项目都看了一遍之后,差不多了解个大概了,因为它设置了自动扫描bean,之后的一切都是通过注解,自动注册bean的,现在它不需要装配Spring配置文件信息,自然也就不需要监听器了