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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM