문서의 이전 판입니다!
logException()
과 buildLogMessage()
메소드를 Override하여 자신이 사용하는 로그 라이브러리에 로그를 남기도록 처리하는 것이 좋다.@ControllerAdvice
에 각종 예외 처리 핸들러(@ExceptionHandler
)를 미리 등록해 두고 component-scan을 하면 자동 에러 처리가 된다.package javabeat.net; import java.io.IOException; import java.sql.SQLException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @ControllerAdvice @EnableWebMvc public class ControllerAdviceTest { @ExceptionHandler(IOException.class) public ModelAndView handleIOException(IOException exception){ ModelAndView andView = new ModelAndView(); andView.setViewName("error"); return andView; } @ExceptionHandler(SQLException.class) public ModelAndView handleSQLException(SQLException exception){ ModelAndView andView = new ModelAndView(); andView.setViewName("error"); return andView; } }