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

xiaoxiao2021-02-28  47

====我的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 /welcome2016-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”日志

   

        

转载请注明原文地址: https://www.6miu.com/read-2623542.html

最新回复(0)