Spring Boot 에러페이지 설정
Spring Boot는 xml 파일을 강요하지 않기 때문에 프로젝트를 생성하면 web.xml 파일이 자동 생성되지 않는다.
물론 web.xml 파일을 만들어 에러페이지를 설정하는 등 방법은 여러가지이다.
다음은 스프링부트에서 에러페이지를 심플하게 설정하는 방법 중 하나이다.
발생하는 에러코드(HttpStatus)에 나타낼 ErrorPage를 설정해 컨테이너에 추가한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | @Configuration public class ErrorConfig { @Bean public EmbeddedServletContainerCustomizer containerCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { ErrorPage error403Page = new ErrorPage(HttpStatus.FORBIDDEN, "/403.html"); ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"); ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html"); container.addErrorPages(error403Page, error404Page, error500Page); } }; } } | cs |
src/main/resources/static 하단 경로에 보여줄 에러페이지를 생성한다.
:설정한 에러코드가 발생하면 해당하는 에러 화면을 보여준다.
'Development > SpringBoot' 카테고리의 다른 글
Spring / Spring Boot 설정 비교 (0) | 2016.05.15 |
---|---|
Spring Boot 외장 톰캣 연동 (0) | 2016.05.14 |
Spring Boot 소개 (0) | 2016.04.17 |