为什么有的SSM项目在web.xml中只通过dispatcherServlet加载所有xml 配置文件?而不是像传统的用Listener加载applicationContext.xml,用dispatcherServlet加载springmvc的配置文件?
这两种方式有什么区别?对生成的上下文有什么影响吗?
只配置DispatcherServlet的方式如下
<!-- 配置DispatcherServlet -->
<servlet>
<servlet-name>seckill-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置springMVC需要加载的配置文件 spring-dao.xml,spring-service.xml,spring-web.xml
Mybatis - > spring -> springmvc -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-*.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>seckill-dispatcher</servlet-name>
<!-- 默认匹配所有的请求 -->
<url-pattern>/</url-pattern>
</servlet-mapping>