Could not open ServletContext resource [/WEB-INF/Dispatcher-servlet.xml]
程序员文章站
2022-04-17 14:37:01
...
在应用SpringMvc时候,不注意常常会出现上述异常,原因:默认的DispatcherServlet在初始化时候会加载Dispatcher-servlet.xml文件,所以如果名字或者路径发生了变化,需要在web.xml中配置,形如:
<servlet>
<servlet-name>Dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/*applicationContext*.xml </param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/*applicationContext*.xml </param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>