스프링 Exception 처리

spring 2015. 11. 2. 22:25

- spring-boot Exception 처리

https://zzangjava.tistory.com/926?category=774099

 

 

- @ControllerAdvice annotation 을 이용한 Exception 처리

 

http://krespo.net/191

 

http://ranestar.tistory.com/14

 

 

<annotation-driven />
<context:component-scan base-package="net.krespo" >

 

 

@ControllerAdvice
public class AnnotationExceptionHandler{

    private final Logger logger = LoggerFactory.getLogger(AnnotationExceptionHandler.class);
    
    @ExceptionHandler(value=Exception.class)
    public ModelAndView handleException(Exception e) {
        logger.info("Exception발생");
        logger.error("Exception", e);
        e.printStackTrace();

        ModelAndView model = new ModelAndView();
        model.addObject("exceptionMsg", "Exception발생");
        model.addObject("methodName", "handleException");
        model.setViewName("exception");
        return model;
    }

    @ExceptionHandler(value=RuntimeException.class)
    public ModelAndView handleRuntimeException(RuntimeException e) {
        logger.info("RuntimeException발생");
        logger.error("RuntimeException", e);
        e.printStackTrace();

        ModelAndView model = new ModelAndView();
        model.addObject("exceptionMsg", "RuntimeException발생");
        model.addObject("methodName", "handleRuntimeException");
        model.setViewName("exception");
        return model;
    }
    @ExceptionHandler(value=BaseException.class)
    public ModelAndView handleBaseException(BaseException e) {
        logger.info("BaseException발생");
        logger.error("BaseException", e);
        e.printStackTrace();

        ModelAndView model = new ModelAndView();
        model.addObject("exceptionMsg", "BaseException발생");
        model.addObject("methodName", "handleBaseException");
        model.setViewName("exception");
        return model;
    }

 

 

====================================================================================================

- ExceptionResolver를 이용한 Exception 처리

 

http://ilikesura.tistory.com/entry/Spring-MVC%EC%9D%98-HandlerExceptionResolver-%EB%A5%BC-%EC%82%AC%EC%9A%A9%ED%95%9C-%EC%98%88%EC%99%B8-%EC%B2%98%EB%A6%AC

 

http://mspark7233.blogspot.kr/2014/04/exception-resolver.html

 

https://groups.google.com/forum/#!msg/ksug/5xeN3gDSbu8/lvuzQ-eN3-MJ

 

http://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc

 

https://code.google.com/p/developerhaus/wiki/SpringException

 

 

====================================================================================================

 

- 스프링에서 SQLException 처리
http://secr.tistory.com/282

 

- jsp 공통 에러페이지 설정

http://jhgan.tistory.com/13

 

- enum을 사용한 에러메시지 코드화

http://homo-ware.tistory.com/m/116

 

- Spring에서 404 에러 처리하기

http://aodis.egloos.com/m/5965716

http://bryan7.tistory.com/455

 

- Spring MVC 예외처리

http://springboot.tistory.com/25

http://springboot.tistory.com/33

http://blog.chakannom.com/2016/01/spring-exception-exceptionhandler.html?m=1

 

====================================================================================================

 

'spring' 카테고리의 다른 글

파일업로드&다운로드  (0) 2015.11.07
response cache 제거  (0) 2015.11.07
spring IoC, DI  (0) 2015.11.01
util:properties, properties.xml 사용 및 확장  (0) 2015.11.01
[jackson] Jackson이용한 json, xml 리턴  (0) 2015.08.03
Posted by 張's blog
,