springboot自定義錯誤頁面
阿新 • • 發佈:2018-08-22
定義 let author ror utf-8 就會 pst bean tco
springboot自定義錯誤頁面
1.加入配置:
@Bean public EmbeddedServletContainerCustomizer containerCustomizer() { return (container -> { ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/401.html"); ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"); ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html"); container.addErrorPages(error401Page, error404Page, error500Page); }); }
2.把401.html等放在sattic文件夾下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>404</title>
</head>
<body>
<h2>這是一個自定義的錯誤頁面!</h2>
</body>
</html>
這樣404頁面就會被換為自定義的頁面了.
springboot自定義錯誤頁面