You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.9 KiB
Java

package egovframework.config;
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.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
/**
* 에러 페이지 설정을 위한 설정 클래스
* 404, 500 등의 HTTP 에러 코드에 대한 커스텀 에러 페이지를 매핑합니다.
*/
@Configuration
public class EgovErrorConfig {
/**
* ErrorPageRegistrar 빈을 생성하여 에러 페이지를 등록합니다.
*
* @return ErrorPageRegistrar 구현체
*/
@Bean
public ErrorPageRegistrar errorPageRegistrar() {
return new ErrorPageRegistrar() {
@Override
public void registerErrorPages(ErrorPageRegistry registry) {
// 404 에러 페이지 설정
ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404");
// 500 에러 페이지 설정
ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500");
// 기타 서버 에러 페이지 설정
ErrorPage error502Page = new ErrorPage(HttpStatus.BAD_GATEWAY, "/error/500");
ErrorPage error503Page = new ErrorPage(HttpStatus.SERVICE_UNAVAILABLE, "/error/500");
ErrorPage error504Page = new ErrorPage(HttpStatus.GATEWAY_TIMEOUT, "/error/500");
// 예외 처리를 위한 에러 페이지 설정
ErrorPage runtimeExceptionPage = new ErrorPage(RuntimeException.class, "/error/500");
// 에러 페이지 등록
registry.addErrorPages(error404Page, error500Page, error502Page, error503Page, error504Page, runtimeExceptionPage);
}
};
}
}