Web Spring 전정프

전자정부프레임워크 Exception 관리 ExceptionHandler 적용 방법

zeuz 2021. 1. 22. 15:02
반응형

 

 

1. ExceptionHandler 클래스 생성 , 전정프 AbstractAnnotationExceptionHandler 상속

 

- 전자정부프레임워크의 AbstractAnnotationExceptionHandler

public abstract class AbstractAnnotationExceptionHandler {

	/** 
	 * Default Exeption handler.
	 * @param e Exception class type
	 * @return ModelAndView object
	 */
	@ExceptionHandler(Exception.class)
	public abstract ModelAndView handleException(Exception e);

	/**
	 * Default RuntimeException handler.
	 * @param e RuntimeException class type
	 * @return ModelAndView object
	 */
	@ExceptionHandler(RuntimeException.class)
	public abstract ModelAndView handleRuntimeException(RuntimeException e);

	/**
	 * BaseException handler.
	 * @param e BaseException class type
	 * @return ModelAndView object
	 */
	@ExceptionHandler(BaseException.class)
	public abstract ModelAndView handleBaseException(BaseException e);

	/**
	 * EgovBizException handler.
	 * @param e EgovBizException class type
	 * @return ModelAndView object
	 */
	@ExceptionHandler(EgovBizException.class)
	public abstract ModelAndView handleEgovBizException(EgovBizException e);

	/**
	 * FdlException handler.
	 * @param e FdlException class type
	 * @return ModelAndView object
	 */
	@ExceptionHandler(FdlException.class)
	public abstract ModelAndView handleFdlException(FdlException e);
}

 

 

- 클래스 생성 및 상속

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

import egovframework.rte.fdl.cmmn.exception.BaseException;
import egovframework.rte.fdl.cmmn.exception.EgovBizException;
import egovframework.rte.fdl.cmmn.exception.FdlException;
import egovframework.rte.ptl.mvc.bind.exception.AbstractAnnotationExceptionHandler;


@ControllerAdvice
public class ExceptionHandler extends AbstractAnnotationExceptionHandler{

	private static final Logger logger = LoggerFactory.getLogger(ExceptionHandler.class);

	@Override
	public ModelAndView handleException(Exception e) {
    	//에러시 처리 자신에 맞게 수정
		e.printStackTrace();
		ModelAndView model = new ModelAndView();
		model.setViewName("egovframework/com/cmm/error/egovError");
		return model;
	}

	@Override
	public ModelAndView handleRuntimeException(RuntimeException e) {
    	//에러시 처리 자신에 맞게 수정  
		e.printStackTrace();
		ModelAndView model = new ModelAndView();
		model.setViewName("egovframework/com/cmm/error/egovError");
		return model;
	}

	@Override
	public ModelAndView handleBaseException(BaseException e) {
    	//에러시 처리 자신에 맞게 수정  
		e.printStackTrace();
		ModelAndView model = new ModelAndView();
		model.setViewName("egovframework/com/cmm/error/egovError");
		return model;
	}

	@Override
	public ModelAndView handleEgovBizException(EgovBizException e) {
    	//에러시 처리 자신에 맞게 수정
		e.printStackTrace();
		ModelAndView model = new ModelAndView();
		model.setViewName("egovframework/com/cmm/error/egovError");
		return model;
	}

	@Override
	public ModelAndView handleFdlException(FdlException e) {
    	//에러시 처리 자신에 맞게 수정
		e.printStackTrace();
		ModelAndView model = new ModelAndView();
		model.setViewName("egovframework/com/cmm/error/egovError");
		return model;
	}

} 

 

2. egov-com-servlet.xml

- 전정프 기본 오류처리 주석 

- @ControllerAdvice 사용할 수 있도록 bean 추가

 

<bean id="exceptionHandlerExceptionResolver" class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver" /> 추가

 

 

 

반응형