SpringBoot(十五)-- 修改SpringBoot默认的错误页面

  将以下代码放置到 main方法中。然后在resources 中的static中新建404.html、405.html,这里可以自定义错误编码,不局限于这两个。

@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
  return (container -> {
    ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
    ErrorPage error405Page = new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, "/405.html");
    container.addErrorPages(error404Page, error405Page);
  });
}
原文地址:https://www.cnblogs.com/xbq8080/p/8660980.html