2014-09-04 151 views
-1

其实我Tomcat服务器上使用eclipse运行Spring MVC的Web应用程序,但同时启动了tomcat我收到以下错误Tomcat的错误,同时运行的Spring MVC Web应用程序

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

我使用下面的XML配置文件

  1. Web.xml中

    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd“>

    <display-name>Spring MVC Form Handling</display-name> 
    
    <servlet> 
        <servlet-name>HelloWeb</servlet-name> 
        <servlet-class> 
         org.springframework.web.servlet.DispatcherServlet 
        </servlet-class> 
    
        <load-on-startup>1</load-on-startup> 
    </servlet> 
    
    <servlet-mapping> 
        <servlet-name>HelloWeb</servlet-name> 
        <url-pattern>/</url-pattern> 
    </servlet-mapping> 
    

2.HelloWeb-servlet.xml中

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

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

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

</bean 
+0

发布您的web.xml和完整的堆栈跟踪 – 2014-09-04 09:20:47

回答

0

错误java.io.FileNotFoundException说,它无法打开/WEB-INF/HelloWeb-servlet.xml
这是典型的当位置错误,并且文件不存在那里。请检查文件名是否正确。也可以尝试在开始时删除斜杠'/'。

编辑: 如果文件是从同一位置引用的,你也可以尝试只HelloWeb-servlet.xml没有目录类型。

+0

嗨,先生,我是新的春天mvc。我正在使用以下xml文件 – user3785340 2014-09-04 09:51:48

+0

嗨,先生,其实我是新来的春天我提供了上述xml文件,请指导我那些文件 – user3785340 2014-09-04 10:09:16

+0

何处引用HelloWeb-servlet.xml(定义)? – FazoM 2014-09-04 10:20:00

1

缺省时,Spring,查找在 /WEB-INF/your-servlet-name-servlet.xml一个文件,如果没有专门的的init-PARAM与名称为 “contextConfigLocation的” 属性指定。 这意味着它取得元素的值并附加-servlet.xml并在WEB-INF中查找它。

例如:

<servlet> 
     <servlet-name>HelloWeb</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/web-application-config.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

这里春拿起在WEB-INF文件夹中的Web应用程序-config.xml文件,因为这是专门规定。如果未指定,则会查找/WEB-INF/HelloWeb-servlet.xml,因为“HelloWeb”是servlet名称。

所以确保你在WEB-INF文件夹中有这个文件。

+0

嗨,先生,我使用了contextConfigLocation但在eclipse中启动tomacat时显示了这个错误。我使用了你提到的配置,但没有工作。 – user3785340 2014-09-05 03:39:52

相关问题