Spring Throws Advice 사용 예

1732 단어 자바springAOP
ThrowsAdvice 이상 차단 에 사용

import java.lang.reflect.Method;

import org.springframework.aop.ThrowsAdvice;

public class DaoThrowsAdvice implements ThrowsAdvice {
	public void afterThrowing(Method m, Object args, Object target,
			Throwable subclass) {
		System.out.println("[DaoThrowsAdvice]: An exception occur: "
				+ subclass.getClass().getSimpleName());
		System.exit(0);
	}
}


프로필

<bean id="beforeDaoAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoMethodBeforeAdvice"></bean>
    <bean id="afterDaoAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoMethodAfterAdvice"></bean>
    <bean id="throwsDaoAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoThrowsAdvice"></bean>
    <bean id="aroundAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoMethodAroundAdvice"></bean>
    
    <bean id="daoAopService" class="org.springframework.aop.framework.ProxyFactoryBean">
    	<property name="target" ref="mybatisDaoBean"></property>
    	<property name="interceptorNames">
    		<list>
    			<value>beforeDaoAdvice</value>
    			<value>afterDaoAdvice</value>
    			<value>throwsDaoAdvice</value>
    			<value>aroundAdvice</value>
    		</list>
    	</property>
    </bean>

전체 프로그램 코드 는 첨부 파일 을 참고 하 십시오.

좋은 웹페이지 즐겨찾기