Spring MVC spring Did not find handler method for 页面显示404问题

          最近项目需求,开始研究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”日志



   

        

    原文作者:Spring MVC
    原文地址: https://blog.csdn.net/llccf/article/details/51096885
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞