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);
  });
}

 

posted @ 2018-03-27 23:16  小葱拌豆腐~  阅读(2631)  评论(0编辑  收藏  举报