zoukankan      html  css  js  c++  java
  • spring boot配置404 和 500错误页面跳转

    我是用的spring boot版本是v2.1.4.RELEASE

    添加以下代码即可对404和500进行重定向:

    package com.handler;
    
    import org.springframework.boot.web.server.ErrorPage;
    import org.springframework.boot.web.server.ErrorPageRegistrar;
    import org.springframework.boot.web.server.ErrorPageRegistry;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.http.HttpStatus;
    /**
     * @author lin.hongwen
     * @date 2021-03-29
     * @Description
     */
    @Configuration
    public class ErrorConfigurar implements ErrorPageRegistrar {
    
        @Override
        public void registerErrorPages(ErrorPageRegistry registry) {
            ErrorPage[] errorPages = new ErrorPage[2];
            errorPages[0] = new ErrorPage(HttpStatus.NOT_FOUND, "/manage/index.html");
            errorPages[1] = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500.html");
            registry.addErrorPages(errorPages);
        }
    }
  • 相关阅读:
    我们是如何实现DevOps的
    cmp命令
    全排列II
    chown命令
    两个数组的交集II
    MVVM模式的理解
    chmod命令
    路径总和
    cat命令
    跳水板
  • 原文地址:https://www.cnblogs.com/linhongwenBlog/p/14591306.html
Copyright © 2011-2022 走看看