기본적으로 에러 핸들러가 있다.

스프링 @MVC 예외 처리 방법

스프링 부트가 기본 제공하는 예외 처리기

에러 컨트롤 예제

@Controller
public class SampleController {

	@GetMapping("/hello")
	public String hello(Model model) {
		model.addAttribute("name", "cmlee");
		// 뷰 페이지 명
		return "hello";
	}

	@GetMapping("/exception")
	public String exception() {
		throw new SampleException();
	}

	@ExceptionHandler(SampleException.class)
	public AppError sampleError(SampleException e) {
		AppError appError = new AppError();
		appError.setMessage("error.app.key");
		appError.setReason("IDK IDK IDK");
		return appError;
	}
}

추가

커스텀 에러 페이지 추가했는데도 왜 안먹히나 했는데

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-error-handling-custom-error-pages