본문 바로가기
IT 개발/SPRING

Spring Boot - 에러페이지 설정 (Custom Error page)

by Love of fate 2021. 11. 1.
728x90
반응형

Spring Boot - 에러페이지 설정 (Custom Error page)

 

스프링 부트 공식 문서 

https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.developing-web-applications.spring-mvc.error-handling

 

Spring Boot Features

Graceful shutdown is supported with all four embedded web servers (Jetty, Reactor Netty, Tomcat, and Undertow) and with both reactive and Servlet-based web applications. It occurs as part of closing the application context and is performed in the earliest

docs.spring.io

 

Tomcat에서 제공되는 에러페이지 (일반적)

스프링부트는 자동 구성을 이용하여 화이트라벨(Whitelabel) 오류 페이지를 기본으로 노출 한다.
화면에 스택트레이스를 표시하는 것보단 괜찮지만, 일반적으로 사이트마다 어울리는 특정 페이지를 제작하여 해당 페이지를 노출하곤 한다. 

 

이렇게 설정하고 싶을 때 애플리케이션 오류 페이지를 사용자 정의 할 수 있는데, 그 방법에 대해 알아 보려고 한다.

스프링부트가 자동으로 구성한 기본 오류 핸들러는 'error'뷰를 찾고, 없을 경우 화이트라벨(Whitelabel) 뷰를 사용한다.
이 에러 페이지는 스프링부트에 의해 만들어진 페이지 이며, 이런 기본적인 에러 처리를 하는 곳이 BasicErrorController 이다.

 

● spring boot 오류 처리 Properties

spring boot 오류 처리 Properties 설명 값 설정
server.error.include-exception 오류 응답에 exception의 내용을 포함할지
여부 
TRUE, FALSE (default : false)
server.error.include-stacktrace 오류 응답에 stacktrace 내용을 포함할지 여부 ALWAYS, NEVER, ON_TRACE_PARAM
(default : never)
server.error.path 오류 응답을 처리할 핸들러(ErrorController)의 path server.error.path = /error
server.error.whitelabel.enabled 브라우저 요청에 대해 서버 오류시 기본으로 노출할 페이지를 사용할지 여부 TRUE, FALSE (default : true)
server.error.include-message 응답시 message 포함 여부 NEVER, ALWAYS, ON_PARAM
(default : NEVER)
server.error.include-binding-errors 응답 시 바인딩된 에러에 대한 표시 여부 NEVER, ALWAYS, ON_PARAM 
(default : NEVER)

 

● 예시)

※ stack trace

 - 익셉션이 발생하였을 때 프로그램이 실행중에 호출한 메소드의 리스트

 

● 실행 결과 : whitelabal.enable : false 이기 때문에 springboot에서 기본으로 제공하는 페이지가 뜨지 않음

 

● include-exception = true,

    include-stacktrace = never, 

    whitelabel.enabled = true

 

● include-exception = true,

    include-stacktrace = always 

    whitelabel.enabled = true

 

728x90
반응형

'IT 개발 > SPRING' 카테고리의 다른 글

IntelliJ - Maven Build 하기  (0) 2021.11.02
Spring - JWT (JSON Web Token)  (0) 2021.11.01
Spring Boot dependency - yml/yaml 파일 구성 및 작성법  (0) 2021.05.21
SSH란  (0) 2021.05.10
SPRING 구성 도구 설치  (0) 2021.03.14