2012-02-15 71 views
-2

我需要知道將基本的XML配置文件放入我的Web-inf文件夾,比如web.XML,以及編寫視圖解析器bean的位置。運行基本Spring MVC應用程序的配置或xml文件是什麼?

如何註冊控制器?

當我運行我的應用程序時,出現錯誤「無法打開servlet上下文資源」。什麼是servlet上下文資源,我在哪裏提及它?

我的web.xml文件是:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

<servlet> 
<servlet-name>springmvc</servlet-name> 
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
<load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
<servlet-name>springmvc</servlet-name> 
<url-pattern>*.html</url-pattern> 
</servlet-mapping> 
<welcome-file-list> 
<welcome-file> 
jsp/index.jsp 
</welcome-file> 


</welcome-file-list> 
</web-app> 

用SpringMVC我是:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 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-2.5.xsd"> 

<bean name="/hello_world.html" class="springmvc.web.HelloWorldController"/> 
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
<property name="prefix" value="/jsp/"/> 
<property name="suffix" value=".jsp"/> 
</bean> 
</beans> 

我只有這兩個XML文件。

我知道我也需要一個spring配置文件。我不知道我需要寫些什麼細節。

+2

Spring有非常好的文檔。你應該讀它。 – bezmax 2012-02-15 10:59:28

+0

@Max我也喜歡參考文檔(http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/htmlsingle/)。但不幸的是,這個文件沒有解釋如何設置一個應用程序。 – Ralph 2012-02-15 13:03:51

回答

0

如果您使用STS(Spring工具套件),那麼您可以創建一個Spring模板項目。 (新項目/ SpringSource工具套件/ Spring模板項目/ -Spring MVC項目)

這包含您需要啓動的所有文件。

相關問題