2012-04-22 2 views
0

난 그냥 스프링 MVC 3를 배우기 시작했습니다 사용할 수 없습니다 내가 바로 내가 최대 this을 얻으려고 노력하고 실행하고있어 간단한 인사 세계 프로그램을, 요청 된 자원 (/)가

을 실행하는 시작에 문제가 있지만, 내가 어떤 이유로

내가 항상 여기이 오류

type Status report 

message/

description The requested resource (/) is not available. 

를 받고 내 servlet-context.xml 파일 야에 대한 캔트

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
     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"> 

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> 

    <!-- Enables the Spring MVC @Controller programming model --> 
    <annotation-driven /> 

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> 
    <resources mapping="/resources/**" location="/resources/" /> 

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> 
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="prefix" value="/WEB-INF/views/" /> 
     <beans:property name="suffix" value=".jsp" /> 
    </beans:bean> 

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



</beans:beans> 

web.xml 파일

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

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters --> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/root-context.xml</param-value> 
    </context-param> 

    <!-- Creates the Spring Container shared by all Servlets and Filters --> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <!-- Processes application requests --> 
    <servlet> 
     <servlet-name>appServlet</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>appServlet</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

</web-app> 

HomeController.java

패키지 com.test.test;

import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 


@Controller 
public class HomeController { 

    @RequestMapping(value = "/") 
    public String home() {  
     return "WEB-INF/views/home.jsp"; 
    } 

} 

나는 Tomcat이 7

사람이 오류를 공동 서명 무엇을 알고 사용 해요? 당신이 당신의 서블릿 컨텍스트에서 구성한으로

+0

디버그 수준에서 로깅과 함께 시작 로그를 확인 했습니까? –

답변

5

@Tenelope 방금 "home"을 반환 할 수 있습니다 "WEB-INF/views/home.jsp";을 반환 할 필요가 없습니다 :

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

당신에게 내 조언 (IDE 같은 일식) 스프링 소스를 다운로드하는 것입니다 :

http://www.springsource.org/springsource-tool-suite-download

을 다운로드 한 후 당신은 단순히 File > New > Spring Template Project > Spring MVC project

로 이동할 수 있습니다

프로젝트 만들기를 마치면 작업 템플릿 프로젝트 (구조화 된 프로젝트, 예제 컨트롤러 파일, 예제보기, pom.xml 등)가 생성됩니다. 예를 들어 "/" 예제를 포함합니다. 그냥 빌드하고 바람둥이에 배포 할 수 있습니다.

이 방법을 통해 이미 작업 예제를 얻었으므로 여기에서 가져올 수 있습니다.

btw. 이 체크 아웃 : 당신이 스프링 MVC와 떨어져 잘 시작하는 데 충분하다

https://github.com/SpringSource/spring-mvc-showcase/blob/master/MasteringSpringMVC3.pdf?raw=true

.

+0

제가 언급 한 스프링 소스 도구와 템플릿을 사용하고 있습니다. '집으로 돌아 가려고했으나 404가 나타납니다. – Tenelope

+0

@Tenelope localhost : 8080/yourwarname /을 사용해 보았습니까? Tomcat 서버의 webapps 디렉토리에있는 .war 파일입니까? – ant

+0

HTML이 전혀없는 빈 페이지 만 반환합니다. 웹 응용 프로그램 디렉토리 – Tenelope