我使用 Spring 3.1.1.RELEASE
按照以下方式配置了spring MVC appweb.xml
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/context/*-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/cgi/*</url-pattern>
</servlet-mapping>
用SpringMVC-servlet.xml中
<context:component-scan base-package="com.pokuri.mvc.controllers"/>
UserController.java
package com.pokuri.mvc.controllers;
@Controller
@RequestMapping("/user")
public class UserController {
@RequestMapping(method=RequestMethod.GET)
@ResponseBody
public String defaultRequest(){
return "It's a default handler method";
}
}
的index.jsp
<a class="action" href="cgi/user">Default Action</a>
Sever登录初始化springmvc app:
23:53:04,406 INFO [DispatcherServlet] FrameworkServlet 'springmvc': initialization started
23:53:04,468 INFO [XmlWebApplicationContext] Refreshing WebApplicationContext for namespace 'springmvc-servlet': startup date [Thu Jun 28 23:53:04 IST 2012]; root of context hierarchy
23:53:04,609 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/context/services-context.xml]
23:53:04,890 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6c4fe: defining beans [dummyService]; root of factory hierarchy
23:53:05,156 INFO [DispatcherServlet] FrameworkServlet 'springmvc': initialization completed in 750 ms
.....
.....
23:56:17,875 WARN [PageNotFound] No mapping found for HTTP request with URI [/springmvc/cgi/user] in DispatcherServlet with name 'springmvc'
当我点击index.jsp中的那个链接时,我收到404错误。我可能做了一个愚蠢的错误。但是,无法跟踪它。有人可以帮助我吗?
答案 0 :(得分:1)
看起来您的DispatcherServlet正在查找以-context.xml
结尾的配置文件。但是您的Spring配置文件名为springmvc-servlet.xml
。