First Configuration Method:<servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet< /servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext*.xml</param-value> </init-param> <load-on-startup >1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> < url-pattern>*.do</url-pattern> </servlet-mapping> Second Configuration Method:<context-param> <param-name>contextconfiglocation</param-name><param-value>classpath:applicationcontext.xml,classpath:* Applicationcontext-*.xml</param-value></context-param><listener><listener-class> org.springframework.web.context.contextloaderlistener</listener-class></listener> Difference: When the context loaded in Contextloaderlistener is successful, spring stores applicationcontext in ServletContext with the key value " Org.springframework.web.context.WebApplicationContext.ROOT "in the attribute. Dispatcherservlet if the value of the Publishcontext property is set to True after the context of the load has been successfully (true by default) The applicationcontext will be stored in the attribute of Org.springframework.web.servlet.FrameworkServlet.CONTEXT. + (Servletname). Conclusion: From the above analysis, it can be seen that the applicationcontext loaded by Dispatcherservlet can be considered as the private context of MVC, Because the key value stored in ServletContext is not the same as the key value that is used by the ApplicationContext loaded through Contextloaderlistener, So if you only use Dispatcherservlet to load the context, if there are places in the program that use Webapplicationcontextutils.getrequiredwebapplicationcontext ( ServletContext) to try to get Applicati
The difference between the Contextloaderlistener and the ApplicationContext loaded by Dispatcherservlet