Spring MVC 出現 Did not find handler method for [uri] 可能的解決方法

在做SpringMVC 測試時發現在配置完全正確

0.相關JAR包完全導入,Tomcat啓動完全成功

1.配置有掃描

 <!-- 處理靜態資源 -->
    <mvc:default-servlet-handler/>
    <!--
    Configures the annotation-driven Spring MVC Controller programming model.
	Note that this tag works in Web MVC only, not in Portlet MVC!

	See org.springframework.web.servlet.config.annotation.EnableWebMvc javadoc for details
	on code-based alternatives to enabling annotation-driven Spring MVC support.
    -->
    <mvc:annotation-driven />
    <!-- 配置包掃描器,掃描@Controller註解的類 -->
    <context:component-scan base-package="com.taotao.controller.*"/>

2.在註解生效,且相應處理該次請求的Controller 已經被實例化(通過重寫構造方法發現)

3.相關方法有RequestMapping註解(method字段與對應請求方式相符合)

    @RequestMapping(value = "/item/cat/list", method = {RequestMethod.POST})
    @ResponseBody
    public List<EasyUITreeNode> list(@RequestParam(value = "id", defaultValue = "0") long parentId) {
        System.out.println("進入了這個方法");
        return itemCatService.listCat(parentId);
    }

4. 相應控制器上看看有沒有@RequestMapping 註解,有並在其中寫上了相應uri路勁(如果你的控制器沒有寫上,而是寫成了@Controller("/item/cat")  那麼肯定是失敗的,我就是心急沒注意看到了這一步就解決了)

看看是不是


後端出現的錯誤:

2017-08-31 21:50:18,895 [http-bio-8080-exec-3] DEBUG [org.springframework.web.servlet.DispatcherServlet] - DispatcherServlet with name 'spring-mvc' processing GET request for [/item/cat/list]
2017-08-31 21:50:18,895 [http-bio-8080-exec-3] DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Looking up handler method for path /item/cat/list
2017-08-31 21:50:18,896 [http-bio-8080-exec-3] DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Did not find handler method for [/item/cat/list]
2017-08-31 21:50:18,896 [http-bio-8080-exec-3] DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Matching patterns for request [/item/cat/list] are [/**]
2017-08-31 21:50:18,896 [http-bio-8080-exec-3] DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - URI Template variables for request [/item/cat/list] are {}
2017-08-31 21:50:18,896 [http-bio-8080-exec-3] DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Mapping [/item/cat/list] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@1697861] and 1 interceptor
2017-08-31 21:50:18,896 [http-bio-8080-exec-3] DEBUG [org.springframework.web.servlet.DispatcherServlet] - Last-Modified value for [/item/cat/list] is: -1
2017-08-31 21:50:18,896 [http-bio-8080-exec-3] DEBUG [org.springframework.web.servlet.DispatcherServlet] - Null ModelAndView returned to DispatcherServlet with name 'spring-mvc': assuming HandlerAdapter completed request handling
2017-08-31 21:50:18,896 [http-bio-8080-exec-3] DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request


頁面出現的錯誤:

HTTP Status 404 - /item/cat/list

type Status report
message /item/cat/list
description The requested resource is not available.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章