linhongwenBlog

我是用的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);
    }
}

 

分类:

技术点:

相关文章:

  • 2021-05-16
  • 2022-01-03
  • 2022-12-23
  • 2021-12-11
  • 2021-08-17
  • 2021-08-27
  • 2021-12-12
  • 2021-08-23
猜你喜欢
  • 2021-10-12
  • 2021-12-12
  • 2021-12-12
  • 2021-11-04
  • 2021-06-09
  • 2021-12-12
  • 2021-06-05
相关资源
相似解决方案