http://blog.****.net/wlwlwlwl015/article/details/48134763
Maven 项目的 classpath 理解
applicationContext.xml放在maven的src/main/resources下,将web.xml中的<param-value>配置如下。
<servlet>
<servlet-name>springMvc</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>2</load-on-startup>
</servlet>
如下异常:Could not open ServletContext resource [/WEB-INF/applicationContext.xml
原因:如果不特意指定参数名为contextConfigLoction的<context-parameter>元素,那么spring的ContextLoderListener监听器就会在/WEB-INF/下去寻找并加载该目录下的名为applicationContext.xml这个文件。
解决:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>