SpringBoot(十五)-- 修改SpringBoot默認的錯誤頁面

  將如下代碼放置到 main方法中。而後在resources 中的static中新建404.html、405.html,這裏能夠自定義錯誤編碼,不侷限於這兩個。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);
  });
}
相關文章
相關標籤/搜索