一,springMVC运行流程
在web.xml的配置中(上篇讲解地址https://blog.csdn.net/hellolianhua/article/details/100204585)可知,监听器加载spring的配置文件。
从以上可以看出,contextConfigLocation加载springmvc-servlet.xml和符合classpath:spring/applicationContext-*.xml格式的文件。classpath代表resource目录下。
二,applicationContext.xml配置文件
tomcat启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点。
紧接着,容器创建一个ServletContext(servlet上下文,全局的),这个web项目的所有部分都将共享这个上下文。可以把ServletContext看成是一个Web应用的服务器端组件的共享内存,在ServletContext中可以存放共享数据。ServletContext对象是真正的一个全局对象,凡是web容器中的Servlet都可以访问容器将<context-param>转换为键值对,并交给servletContext。
容器创建<listener>中的类实例,创建监听器。 listener中ContextLoaderListener监听器的作用就是启动Web容器时,监听servletContext对象的变化,获取servletContext对象的<context-param>,来自动装配ApplicationContext的配置信息。(即加载applicationContext.xml文件)
那么applicationContext.xml的配置文件,在此项目中,我将applicationContext.xml的配置文件分为了四个,其中springmvc-servlet.xml,spring/applicationContext-dao.xml,spring/applicationContext-service.xml,spring/applicationContext-shiro.xml.
参考原文链接:https://blog.csdn.net/qq_35571554/article/details/82453684