2014-09-04 138 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

相關問題