@ControllerAdvice를 선언한 클래스 예
Example04Controller.java
package com.springmvc.chap10;
...
@Controller
public class Example04Controller {
@GetMapping("/exam04")
public void handleRequest() {
throw new Example03Exception();
}
}
Example04Exception.java
package com.springmvc.chap10;
import org.springframework.web.bind.annotation.ControllerAdvice;
...
@ControllerAdvice(basePackages={"com.springmvc"})
public class Example04Exception {
@ExceptionHandler(value={RuntimeException.class})
private ModelAndView handleErrorMethod(Exception ex) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("errorMassage", "Example04Exception 메시지입니다");
modelAndView.addObject("exception", ex);
modelAndView.setViewName("webpage10_03");
return modelAndView;
}
}