【发布时间】:2011-07-17 12:16:42
【问题描述】:
我正在尝试使用 Spring 3.0 映射控制器但没有成功。我有以下错误:
2011-07-17 20:01:16,536 [http-8080-exec-5] 警告 org.springframework.web.servlet.PageNotFound - 未找到带有 URI [/sherd/cp/index] 的 HTTP 请求的映射名称为“cp”的 DispatcherServlet
如何调试此错误?我已将日志设置为 INFO 并看到:
2011-07-17 20:10:28,402 [main] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - 将 URL 路径 [/cp/index] 映射到处理程序“索引” 2011-07-17 20:10:28,402 [main] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - 映射到处理程序“索引”的 URL 路径 [/cp/index.*] 2011-07-17 20:10:28,402 [main] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - 将 URL 路径 [/cp/index/] 映射到处理程序“索引”
但是,我在尝试加载页面时收到上面显示的 WARN。
WEB-INF/web.xml的相关部分如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/cp-beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>cp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cp</servlet-name>
<url-pattern>/cp/*</url-pattern>
</servlet-mapping>
我的 WEB-INF/cp-servlet.xml 包含以下内容:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.obliquid.sherd.web.cp"/>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
</beans>
而WEB-INF/cp-beans.xml暂时基本是空的:
<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-3.0.xsd">
</beans>
我在包org.obliquid.sherd.web.cp中定义了类Index
package org.obliquid.sherd.web.cp;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* Spring MVC controller for /cp/index
*
* @author stivlo
*/
@Controller
@RequestMapping("/cp/index")
public class Index {
@RequestMapping
public String show() {
return "cp/index"; //view
}
}
我错过了什么吗?
【问题讨论】: