springmvc No mapping found for HTTP request with URI in Dispatc

springmvc No mapping found for HTTP request with URI in Dispatc

博客分类:  Java Web
springmvc spring MVC No mapping found url-pattern

项目是使用spring MVC

(1)在浏览器中访问,后台总报错:

Java代码   收藏代码
  1. No mapping found for HTTP request with URI [/exam3/welcome] in DispatcherServlet with name 'spring2'  

 查了好半天,才发现是controller 没有扫描到

我是使用的注解。

spring mvc配置文件如下:

Xml代码   收藏代码
  1. xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  
  4.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
  5.     xmlns:mvc="http://www.springframework.org/schema/mvc"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans  
  7.            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd  
  8.             http://www.springframework.org/schema/context  
  9.            http://www.springframework.org/schema/context/spring-context-3.2.xsd  
  10.            http://www.springframework.org/schema/aop  
  11.            http://www.springframework.org/schema/aop/spring-aop-3.2.xsd  
  12.            http://www.springframework.org/schema/tx   
  13.            http://www.springframework.org/schema/tx/spring-tx-3.2.xsd  
  14.            http://www.springframework.org/schema/mvc   
  15.            http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"  
  16.            >  
  17.   
  18.       
  19.     <bean  
  20.         class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />  
  21.   
  22.       
  23.     <bean  
  24.         class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />  
  25.       
  26.     <bean  
  27.         class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  28.         <property name="viewClass"  
  29.             value="org.springframework.web.servlet.view.JstlView" />  
  30.         <property name="prefix" value="/WEB-INF/jsp/" />  
  31.         <property name="suffix" value=".jsp" />  
  32.     bean>  
  33. <mvc:annotation-driven />  
  34.     
  35.   
  36. <context:component-scan base-package="com"/>  
  37. beans>  

 controller 的目录结构如下:


springmvc No mapping found for HTTP request with URI in Dispatc_第1张图片
 

 

(2)这个问题解决之后,又报错:

No mapping found for HTTP request with URI [/exam3/WEB-INF/jsp/welcome.jsp] in DispatcherServlet with name 'spring2'

结果发现是web.xml配置得有问题,下面是有问题的:

Xml代码   收藏代码
  1. <servlet>  
  2.         <servlet-name>spring2servlet-name>  
  3.         <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>  
  4.         <load-on-startup>1load-on-startup>  
  5.     servlet>  
  6.     <servlet-mapping>  
  7.         <servlet-name>spring2servlet-name>  
  8.         <url-pattern>/*url-pattern>  
  9.     servlet-mapping>  

 解决方法:把url-pattern 由/* 改为/

  • 查看图片附件
5 
4 
分享到:   
date java.lang.IllegalArgumentException: ... |  启动tomcat报错org.hibernate.cache.CacheP ...
  • 2013-09-26 14:00
  • 浏览 92247
  • 评论(7)
  • 分类:编程语言
  • 相关推荐
参考知识库
Unity3D知识库 143  关注 | 118  收录
Oracle知识库 450  关注 | 231  收录
Scala知识库 386  关注 | 848  收录
Linux知识库 1815  关注 | 1512  收录
评论
7 楼  spring_springmvc 2015-07-25  
spring mvc demo教程源代码下载,地址:
http://www.zuidaima.com/share/kspringmvc-p1-s1.htm
6 楼  lt26i 2015-05-29  
解决问题了,谢谢!
5 楼  hw1287789687 2015-03-26  
yigeyanse 写道
ri,第一个怎么改的?

Java代码   收藏代码
  1. package="com"/>   

改包名啊,因为配置文件中扫描的是 com包名下面的,但是我的控制器包名是 web.controller,所以扫描不到啊
4 楼  yigeyanse 2015-03-25  
ri,第一个怎么改的?
3 楼  u013585587 2014-09-06  
2楼的你现在应该知道为什么是/而不是/*了吧。。
2 楼  qingfeng812 2014-04-01  
解决方法:把url-pattern 由/* 改为/


你就不能访问动态资源了,呵呵!要知道为什么改,改什么?
1 楼  abccyz 2013-12-19  
哥们没办法截图就直接上代码了:
- Finished creating instance of bean 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping'
>>> 2013-12-19 19:41:52,053 DEBUG [main] (DispatcherServlet.java:549) - No HandlerMappings found in servlet 'Lab_Matrix': using default
>>> 2013-12-19 19:41:52,055 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:430) - Creating instance of bean 'org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter'
>>> 2013-12-19 19:41:52,055 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter'
>>> 2013-12-19 19:41:52,057 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:430) - Creating instance of bean 'org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter'
>>> 2013-12-19 19:41:52,057 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter'
>>> 2013-12-19 19:41:52,062 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:430) - Creating instance of bean 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter'
>>> 2013-12-19 19:41:52,611 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter'
>>> 2013-12-19 19:41:52,611 DEBUG [main] (DispatcherServlet.java:587) - No HandlerAdapters found in servlet 'Lab_Matrix': using default
>>> 2013-12-19 19:41:52,616 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:430) - Creating instance of bean 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver'
>>> 2013-12-19 19:41:52,635 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver'
>>> 2013-12-19 19:41:52,644 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:430) - Creating instance of bean 'org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver'
>>> 2013-12-19 19:41:52,645 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver'
>>> 2013-12-19 19:41:52,647 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:430) - Creating instance of bean 'org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver'
>>> 2013-12-19 19:41:52,649 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver'
>>> 2013-12-19 19:41:52,649 DEBUG [main] (DispatcherServlet.java:626) - No HandlerExceptionResolvers found in servlet 'Lab_Matrix': using default
>>> 2013-12-19 19:41:52,651 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:430) - Creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
>>> 2013-12-19 19:41:52,652 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
>>> 2013-12-19 19:41:52,652 DEBUG [main] (DispatcherServlet.java:647) - Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@159ed86]
>>> 2013-12-19 19:41:52,659 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:430) - Creating instance of bean 'org.springframework.web.servlet.view.InternalResourceViewResolver'
>>> 2013-12-19 19:41:52,673 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'org.springframework.web.servlet.view.InternalResourceViewResolver'
>>> 2013-12-19 19:41:52,673 DEBUG [main] (DispatcherServlet.java:687) - No ViewResolvers found in servlet 'Lab_Matrix': using default
>>> 2013-12-19 19:41:52,677 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:430) - Creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
>>> 2013-12-19 19:41:52,678 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
>>> 2013-12-19 19:41:52,690 DEBUG [main] (DispatcherServlet.java:709) - Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager@69d6be]
>>> 2013-12-19 19:41:52,690 DEBUG [main] (FrameworkServlet.java:523) - Published WebApplicationContext of servlet 'Lab_Matrix' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.Lab_Matrix]
>>> 2013-12-19 19:41:52,690  INFO [main] (FrameworkServlet.java:463) - FrameworkServlet 'Lab_Matrix': initialization completed in 5648 ms
>>> 2013-12-19 19:41:52,691 DEBUG [main] (HttpServletBean.java:136) - Servlet 'Lab_Matrix' configured successfully


能分析这个是啥原因吗   现在是发请求不到控制层

控制台打印这个:
(DispatcherServlet.java:819) - DispatcherServlet with name 'Lab_Matrix' processing GET request for [/Lab_Matrix/index.do]
WARN [http-8080-1] (DispatcherServlet.java:1080) - No mapping found for HTTP request with URI [/Lab_Matrix/index.do] in DispatcherServlet with name 'Lab_Matrix'
DEBUG [http-8080-1] (FrameworkServlet.java:913) - Successfully completed request


帮忙分析下这是什么原因

你可能感兴趣的:(Spring,MVC)