2013-03-22 41 views
1

Springs MVC。我試圖捕捉404頁面錯誤,但代碼沒有編碼。我錯過了什麼嗎?Springs MVC。我試圖捕捉404頁面錯誤,但代碼沒有編碼

@ControllerAdvice 
public class GeneralHandler 
{ 
    private static final Logger LOGGER = getLogger(GeneralHandler.class); 


    @ExceptionHandler 
    public ModelAndView handleException (NoSuchRequestHandlingMethodException ex) { 

     LOGGER.warn(ex.toString()); 
     return new ModelAndView("404"); 
    } 
} 

回答

2

看來,它不能做到使用@ExceptionHandlerhttps://stackoverflow.com/a/3230559/322166

取而代之的是,你需要配置該行爲您web.xml

<error-page> 
    <error-code>404</error-code> 
    <location>/your-error-page.html</location> 
</error-page>