spring mvc page not found no mapping found for http request with uri

本文讨论了在使用Spring MVC框架时遇到的路径匹配错误,并提供了解决方案。通过调整配置文件中的注解映射设置,成功解决了路径不匹配的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我这里的报错实际情况是:

14:02:15,736 WARN  [PageNotFound] No mapping found for HTTP request with URI [/spring3MVC/abc/index.do] in DispatcherServlet with name 'spring3MVC'

其中,[spring3MVC/abc/index.do]是我请求的路径,就我现在的项目,我的请求路径是:

http://localhost:8080/spring3MVC/abc/index.do


spring3MVC是我的项目名,abc是action的注解用的,index是方法的注解

@Controller
@RequestMapping("/abc")
public class ZhujieRequestController  {

    protected final transient Log log = LogFactory.getLog(ZhujieRequestController.class);

    @RequestMapping("/index")
    public String index() {
        return "hello";
    }

}

其它的配置文件,比如web.xml和一些jdbc连接的我就不说了,就说核心xml文件:spring3MVC-servlet.xml

<?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:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	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.1.xsd   
    http://www.springframework.org/schema/tx   
    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-3.1.xsd  
    http://www.springframework.org/schema/mvc  
    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">




	<!--自动扫描的包名 -->
	<context:component-scan base-package="com.ideawu" />

	<!-- 默认的注解映射的支持 -->
	<!-- <mvc:annotation-driven /> -->

	<!-- 视图解释类 -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/" />
		<property name="suffix" value=".jsp" />
		<!--
			可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑
		-->
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
	</bean>

	
	

	<!-- 通过注解请求action里面的方法-->
	<bean id="annotationHandlerMapping"
		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
		<property name="order" value="0" />
		<property name="useDefaultSuffixPattern" value="false" /><!--请注意这里,value="false",就因为这个false,我从早上8点,弄到下午2点-->
		
	</bean>


	
	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
</beans>	
基本配置就是这样,服务重启了好多变,总是不行,后来,我把
<property name="useDefaultSuffixPattern" value="false" />
的value改为true,就正常了。 哎,我也是刚学,碰到这个问题。   还好运气好,搞定了

这个错误信息通常出现在使用Spring框架的Web应用程序中,特别是当使用了Spring MVC时。`DispatcherServlet.noHandlerFound` 错误表示请求的URL没有找到对应的处理器(handler)。具体来说,这个错误信息表明有一个HTTP请求发送到服务器的`/untitled30_war_exploded`路径,但是没有找到对应的处理器来处理这个请求。 这个错误通常由以下几个原因引起: 1. **URL路径配置错误**:请求的URL路径没有在Spring MVC的控制器(Controller)中定义对应的处理方法。 2. **控制器未正确扫描**:Spring容器没有扫描到对应的控制器类,导致无法找到处理请求的方法。 3. **视图解析器配置问题**:视图解析器配置不正确,导致无法找到对应的视图。 解决方法如下: 1. **检查URL路径**:确保请求的URL路径在控制器中有对应的处理方法。例如,如果请求的URL是`/untitled30_war_exploded/hello`,那么在控制器中应该有对应的`@RequestMapping`注解的方法来处理这个请求。 ```java @Controller public class HelloController { @RequestMapping("/hello") public String hello() { return "hello"; } } ``` 2. **确保控制器被扫描**:确保你的控制器类在Spring的扫描路径中,可以通过在配置类上使用`@ComponentScan`注解来扫描控制器所在的包。 ```java @Configuration @ComponentScan(basePackages = "com.example.controller") public class AppConfig { } ``` 3. **检查视图解析器配置**:确保视图解析器配置正确,能够找到对应的视图文件。 ```xml <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean> ``` 通过以上步骤,可以逐步排查并解决`DispatcherServlet.noHandlerFound`错误。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值