从控制台接收此错误:
*org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from ServletContext resource
[/WEB- INF/spring-dispatcher-servlet.xml]; nested exception is
java.io.FileNotFoundException: Could not open ServletContext resource
[/WEB-INF/spring-dispatcher-servlet.xml]*
这是我收到的错误:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>fj21-tarefas</display-name>
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
我在做
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context.xml</param-value>
</init-param>
从springmvc更改默认上下文,但是它不起作用。这里已经采取了一些建议,将servlet名称标签写入文件name-context.xml约定中,同样的错误。
您应该尝试更改servlet名称。预期的Spring Web上下文元数据XML文件名应为servletname-servlet.xml
,这是在Spring 4之前的预期文件名,不确定在Spring 5中是否已更改。。由于您的Servlet名称为springmvc
,因此文件名应为springmvc-servlet.xml
。
使您的web.xml看起来像这样,直接取自Spring文档: