본문 바로가기
Spring

Spring ExceptionResolver

by 자바초보자 2015. 10. 7.
728x90

Spring ExceptionResolver

Spring ExceptionResolver
===>Exception에 따라 error jsp를 맵핑하여 처리한다
===>500에러 발생시 캐치되어 상태가 200으로 정상처리된다.
===>Exception별로 처리 가능
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"><property name="defaultErrorView" value="egovframework/com/cmm/error/egovError"/><property name="exceptionMappings"><props><prop key="egovframework.com.cop.common.AuthWizardException">egovframework/com/cmm/error/auth_wizard_message</prop><prop key="org.springframework.dao.DataAccessException">egovframework/com/cmm/error/dataAccessFailure</prop><prop key="org.springframework.transaction.TransactionException">egovframework/com/cmm/error/dataAccessFailure</prop><prop key="egovframework.rte.fdl.cmmn.exception.EgovBizException">egovframework/com/cmm/error/egovBizException</prop><prop key="org.springframework.web.HttpSessionRequiredException">egovframework/com/uat/uia/EgovLoginUsr</prop></props></property></bean>
package egovframework.com.cop.common;
import org.springframework.core.NestedRuntimeException;
public class AuthWizardException extends NestedRuntimeException{
public AuthWizardException(String message){
super(message);
}
public String getMessage(){
return super.getMessage();
}
}
@Before("execution(* egovframework.com.cop..web.*MstController.*(..))")
public void managerAuthCheck(JoinPoint joinPoint) throws AuthWizardException {
K2UtilBean.SystemOutPrintln("**** AOP Advice managerAuthCheck ******");
/*
HttpServletResponse response = this.getResponse(joinPoint);
if(response == null){
String msg = "Controller Class의 action Method에 response를 파라메터로 추가하세요";
request.setAttribute("message", msg);
throw new AuthWizardException(msg);
}
*/
String siteId = request.getParameter("siteId");
AuthCheck auth = new AuthCheck(request);
if(!auth.siteManagerCheck(siteId)){
request.setAttribute("message", auth.getMessage());
//강제 Exception 발생 ->SimpleMappingExceptionResolver
// ->AuthWizardException ->egovframework/com/cmm/error/auth_wizard_error
throw new AuthWizardException(auth.getMessage());
}
}
728x90

'Spring' 카테고리의 다른 글

[Spring] AOP를 이용한 속도 측정  (0) 2015.10.07
spring bean 객체 얻어오기  (0) 2015.10.07
Spring 다국어 변경  (0) 2015.10.07
Spring schedule  (0) 2015.10.07
[Spring] UrlBasedViewResolver 다중 설정  (0) 2015.10.07