您的位置:首页 > 编程语言 > Java开发

springmvc-springboot配置全局异常跳转页

2017-11-07 14:16 597 查看
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;

import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;

import org.springframework.boot.web.servlet.ErrorPage;

import org.springframework.context.annotation.Configuration;

import org.springframework.http.HttpStatus;

/**

 * 

 * 

 * @Description: 全局异常跳转页面

 * 

 */

@Configuration

public class ErrorConfig implements EmbeddedServletContainerCustomizer {

@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404");
ErrorPage error505Page = new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, "/error/405");
ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500");
container.addErrorPages(error404Page, error505Page, error500Page);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息