I’m trying to map a Controller with Spring 3.0 without success. I’ve the following error:
2011-07-17 20:01:16,536 [http-8080-exec-5] WARN org.springframework.web.servlet.PageNotFound – No mapping found for HTTP request with URI [/sherd/cp/index] in DispatcherServlet with name ‘cp’
How I debug this error? I’ve set the log to INFO and saw:
2011-07-17 20:10:28,402 [main] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping – Mapped URL path [/cp/index] onto handler ‘index’
2011-07-17 20:10:28,402 [main] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping – Mapped URL path [/cp/index.*] onto handler ‘index’
2011-07-17 20:10:28,402 [main] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping – Mapped URL path [/cp/index/] onto handler ‘index’
However, I get the WARN shown above when trying to load the page.
The relevant part of WEB-INF/web.xml is the following:
<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>
I’ve WEB-INF/cp-servlet.xml with the following content:
<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>
And WEB-INF/cp-beans.xml is basically empty for now:
<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>
I’ve defined the class Index in the package org.obliquid.sherd.web.cp
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
}
}
Am I missing something?
I’ve managed to make it work with the following changes:
Notice that I’ve removed the /cp prefix in @RequestMapping and in the logical view name returned. Also, in cp-servlet.xml I’ve added the following: