`

springmvc No mapping found for HTTP request with URI in Dispatc

阅读更多

项目是使用spring MVC

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

No mapping found for HTTP request with URI [/exam3/welcome] in DispatcherServlet with name 'spring2'

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

我是使用的注解。

spring mvc配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<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"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	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/context
           http://www.springframework.org/schema/context/spring-context-3.2.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
           http://www.springframework.org/schema/mvc 
           http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"
           >

	<!-- HandlerMapping -->
	<bean
		class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />

	<!-- HandlerAdapter -->
	<bean
		class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
	<!-- ViewResolver -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>
<mvc:annotation-driven />
<!-- 处理器 -->  
<!-- <bean name="/hello" class="com.mvc.jn.controller.HelloWorldController"/> -->
<context:component-scan base-package="com"/>
</beans>

 controller 的目录结构如下:



 

 

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

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

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

<servlet>
		<servlet-name>spring2</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>spring2</servlet-name>
		<url-pattern>/*</url-pattern>
	</servlet-mapping>

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

  • 大小: 25.1 KB
6
4
分享到:
评论
6 楼 lt26i 2015-05-29  
解决问题了,谢谢!
5 楼 hw1287789687 2015-03-26  
yigeyanse 写道
ri,第一个怎么改的?

<context:component-scan base-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


帮忙分析下这是什么原因

相关推荐

Global site tag (gtag.js) - Google Analytics