将以下代码放置到 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);
  });
}

 

相关文章:

  • 2021-11-05
  • 2021-08-19
  • 2021-12-12
  • 2021-06-08
  • 2021-11-23
  • 2021-04-01
  • 2021-04-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-11
  • 2021-05-04
  • 2021-11-29
  • 2022-12-23
  • 2021-11-23
相关资源
相似解决方案