我学习Spring MVC和因为在这个问题了几个小时,我阻止,应该有一个明显的分辨率:警告:未找到HTTP请求的URI与org.springframework.web.servlet.PageNotFound noHandlerFound映射
我在web.xml中定义了DispatcherServlet springSoccer并在SpringSoccer-servlet.xml中的WEB-INF目录下进行配置。
在springSoccer-servlet.xml中我配置ViewResolver,设置指向我控制器包的组件扫描。
我部署到Tomcat 8.0,当我指出我的浏览器http://localhost:8080/SoccerSpringMaven3/springSoccer/users/我收到错误:
Nov 19, 2015 9:07:50 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SoccerSpringMaven3/springSoccer/users] in DispatcherServlet with name 'springSoccer'
这只是一个没有找到我的RequestMapping的问题。找到配置如下:
的web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!-- Source project: sip05, branch: 01 (Maven Project) -->
<servlet>
<servlet-name>springSoccer</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springSoccer</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
springSoccer-servlet.xml中
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:component-scan base-package="com.spring.soccer.controller" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
</beans>
SoccerController.xml
package com.spring.soccer.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class SoccerController {
@RequestMapping("/users")
public String printSoccerHome(ModelMap model) {
return "HelloSoccer";
}
}
任何指针?非常感谢。
注解你的方法,你不应该来注解你'SoccerController'用' @RequestMapping(“/ SoccerSpringMaven3/SpringSoccer”)'为了这个工作?或直接调用'http:// localhost:8080/users'?调用'HandlerMapping'时,'DisptatcherServlet'找不到'SoccerSpringMaven3 /'映射。 – RK1
案件事宜!!!!!!!!!!!!!试试/ SoccerSpringMaven3/springSoccer /用户 – jny
RK1谢谢。我尝试过,但它不起作用,我的理解是,首先获取URI的上下文根,然后是servlet名称,然后是我放入RequestMapping的任何东西。我在POM中定义的上下文根是 SoccerSpringMaven3 那么ServletNAme是springSoccer。 –