web.xml中加载spring的applicationContext.xml

还是要好好看官方文档的。

  在web.xml中启动spring的三种方式:使用ContextLoaderServlet,ContextLoaderListener

在spring3之后的版本中,去掉ContextLoaderServlet 启动方式。所以使用ContextLoaderListener方式。

ContextLoaderListener方式: 

    <!-- 加载applicationcontext.xml -->
   <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!--contextConfigLocation在 ContextLoaderListener类中的默认值是 /WEB-INF/applicationContext.xml --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> <!-- <param-value>classpath:applicationContext*.xml</param-value> --> </context-param>

原文地址:https://www.cnblogs.com/July74/p/6089123.html