Spring MVC 404 Not Found 無錯誤記錄檔解決方案,mvc404

來源:互聯網
上載者:User

Spring MVC 404 Not Found 無錯誤記錄檔解決方案,mvc404

情境描述,使用Spring MVC 架構,進行資料儲存,用firefox的firebug跟蹤發現404 Not Found。

 

 分析:後台沒有列印任何錯誤記錄檔,無法分析問題所在。


解決方案(由我朋友提供)

在spring-mvc.xml 設定檔中 加上一下紅色部分的設定檔。


在controller 下面添加 ControllerAdviceTest.java 檔案(注意:必須是controller下面,因為在spring-mvc.xml 中配置了 component-scan)



再次運行 後台輸出以下錯誤記錄檔


很明顯表明,對象名稱有問題,至此問題解決。附件:附上ControllerAdviceTest.java 源碼(不能添加壓縮包嗎? 請自行修改bag名)

package com.snake.controller;import org.apache.log4j.Logger;import org.springframework.http.HttpStatus;import org.springframework.web.bind.annotation.ControllerAdvice;import org.springframework.web.bind.annotation.ExceptionHandler;import org.springframework.web.bind.annotation.ResponseStatus;import org.springframework.web.context.request.NativeWebRequest;@ControllerAdvicepublic class ControllerAdviceTest {protected static Logger logger = Logger.getLogger(ControllerAdviceTest.class);    @ExceptionHandler(Exception.class)    @ResponseStatus(HttpStatus.BAD_REQUEST)    public String processUnauthenticatedException(NativeWebRequest request,Exception e) {    logger.error(e.getMessage());        return "viewName"; //返回一個邏輯視圖名    }}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.