1

弹簧 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");
    }
}
4

1 回答 1

2

似乎无法使用@ExceptionHandlerhttps ://stackoverflow.com/a/3230559/322166

取而代之的是,您需要在以下配置中配置该行为web.xml

<error-page>
    <error-code>404</error-code>
    <location>/your-error-page.html</location>
</error-page>
于 2013-03-22T13:08:34.770 回答