Spring MVC spring Did not find handler method for 页面显示404问题【熟悉这个,才能定位问题不是freeMarker问题】


====我的mvc controller组件扫描位置:

<!-- 扫描所有controller组件 -->
    <context:component-scan base-package="com.ybl.**.controller" />
这就限制了 我的 
FreeMarkerTest

类的存放目录。确实是这个问题。



====转自:https://blog.csdn.net/llccf/article/details/51096885


====

最近项目需求,开始研究spring ,struts等框架,照着网上小例子配置,不甚懂的原理的情况下配起来真是麻烦啊

       环境: spring MVC , javaEE7.0  Spring 3.1.1

                    src目录是 

     package  com.mvc.rest

                  RestController.javac

     问题:

       打网页显示为:http://localhost:8080/springMVC/welcome

HTTP Status 404 -

type Status report

message

description The requested resource is not available.


  console: 日志为

2016-04-08 15:21:47 Looking up handler method for path /welcome
2016-04-08 15:21:47 Did not find handler method for [/welcome]
2016-04-08 15:21:47 No mapping found for HTTP request with URI [/springMVC/welcome] in DispatcherServlet with name 'spring'
2016-04-08 15:21:47 Successfully completed request


网上查了各种解决方法,最后定为问题是:

解决1:

<mvc:annotation-driven/>
       <context:component-scan base-package="com.mvc.rest/*"></context:component-scan>

   改为

<mvc:annotation-driven/>
       <context:component-scan base-package="com.mvc.rest"></context:component-scan>

  去掉/*

解决2: 

        或者改为

        <mvc:annotation-driven/>

       <context:component-scan base-package="com.mvc.*"></context:component-scan>

    

    原因component-scan base-package配置的是路径名称

           如  value='com.mvc.rest'  则 扫描这个包路径下的java bean, 如果配置的 com.mvc.*  则扫描com.mvc包下的子包, 如果是com.mvc.rest.*则扫描com.mvc.rest

下所有的子包,因为com.mvc.rest没有子包,所以此处显示“Did not find handler method for”日志





   

        


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值