2010-07-07 7 views
0

나는이 패키지 org.spring.test입니다 봄 3 MVC를 시도하고 코드는왜 봄 경고 메시지가 "org.springframework.web.servlet.PageNotFound"입니까?

@Controller 
@RequestMapping("/welcome") 
public class WelcomeController { 

private Logger logger = org.slf4j.LoggerFactory.getLogger(WelcomeController.class); 


@RequestMapping(method = RequestMethod.GET) 
public void welcome() { 
    logger.info("Welcome!"); 
} 
@RequestMapping("test1") 
public void test1() { 
    logger.info("test1!"); 
} 
@RequestMapping("test2") 
public void test2() { 
    logger.info("test2!"); 
} 
} 

web.xml 파일은 다음과 같습니다

<servlet> 
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/spring/*.xml 
     </param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
    <url-pattern>/*</url-pattern> 
</servlet-mapping> 

마지막 mvc.xml이

<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/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-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="org.spring.test" /> 
<!-- Configures support for @Controllers --> 
<mvc:annotation-driven /> 

<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory --> 
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/views/"/> 
    <property name="suffix" value=".jsp"/> 
</bean> 

입니다

"mvn jetty : run"명령을 사용하여 012로 쓸 때

INFO : org.spring.test.WelcomeController - Welcome! 
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/springdemo/WEB-INF/views/welcome.jsp] in DispatcherServlet with name 'Spring MVC Dispatcher Servlet' 

이유 : 32,158, 는

"HTTP ERROR 404 
Problem accessing /springdemo/WEB-INF/views/welcome.jsp. Reason: 
NOT_FOUND" 

콘솔 메시지는 무엇입니까?

+0

참조 http://stackoverflow.com/questions/2977446/tiles-2-and-no-mapping-found-for-http-request-with-uri-spring-mvc/2977549#2977549 – axtavt

답변

2

/WEB-INF/views/test.jsp가 누락 된 것 같습니다. 그게 사실이야?

컨트롤러 클래스에 매핑되지 않은 URI를 요청하고 있습니다 (/ welcome에 매핑 됨). Spring은 InternalResourceViewResolver를 사용하여 요청을 처리한다. 접두어 + "test"+ 접미사가 필요합니다. 그것이 /WEB-INF/views/test.jsp로 끝나는 방법입니다.

해당 JSP가 있는지 확인하거나 컨트롤러 매핑을 변경하십시오.

업데이트 : 질문을 변경했습니다. 하지만 /springdemo/WEB-INF/views/welcome.jsp가 있습니까?

+0

안녕하세요,이 데모 나는 SpringPlugin으로 복사한다. (새로운 Springtemplate은 SpringMvcProject이다.) – EdwardLau

관련 문제