0

当我在 Glassfish 4/Tomcat 8 上部署我的第一个 Spring MVC 应用程序时,我收到了这个错误

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/myFirstSpring-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/myFirstSpring-servlet.xml]

我认为是我的 Servlet 配置有问题。

web.xml

    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
  <display-name>MyDemoApp</display-name>
    <servlet>
  <servlet-name>myFirstSpring</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
  <param-name>contexConfiguration</param-name>
  <param-value>/WEB-INF/config/myDemoApp-servletConfig.xml</param-value>
  </init-param>
  </servlet>
  <servlet-mapping>
  <servlet-name>myFirstSpring</servlet-name>
  <url-pattern>*.html</url-pattern>
  </servlet-mapping>

</web-app>

我的 spring bean 配置文件名为 myDemoApp-servletConfig.xml。

[![<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<mvc:annotation-driven></mvc:annotation-driven>

<context:component-scan base-package="com.demo.controllers"></context:component-scan>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="WEB=INF/jsp"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>][1]][1]

在此处输入图像描述

关于我做错了什么的任何线索?

真挚地,

4

1 回答 1

0

myFirstSpring-servlet.xml放在您的 WEB-INF 文件夹中。如果您这样做但仍然无法正常工作,请清理您的项目并重试。

于 2018-05-11T14:48:41.987 回答