首页 > 编程语言 > 详细

springboot自定义错误页面

时间:2018-08-21 23:23:52      阅读:160      评论:0      收藏:0      [点我收藏+]

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自定义错误页面

原文:https://www.cnblogs.com/charlypage/p/9515080.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!