出現(xiàn)問題的原因
配置Maven項目,我把spring相關的xml都放到了resources下端礼,但是spring默認會去web-inf下尋找xml,所以才會出現(xiàn)錯誤
Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
解決方法
在web.xml里指定spring相關xml的加載
正確的web.xml里spring加載設置
<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>
<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>1</load-on-startup>
</servlet>