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");
}
}
答案 0 :(得分:2)
似乎无法使用@ExceptionHandler
:https://stackoverflow.com/a/3230559/322166
而不是那样,您需要在web.xml
中配置该行为:
<error-page>
<error-code>404</error-code>
<location>/your-error-page.html</location>
</error-page>