AOPケース(b)は例外クラスのセクション

パッケージcom.jt.aop。

輸入org.aspectj.lang.JoinPoint;
輸入org.aspectj.lang.ProceedingJoinPoint;
輸入org.aspectj.lang.annotation.AfterThrowing。
輸入org.aspectj.lang.annotation.Around;
輸入org.aspectj.lang.annotation.Aspect;
輸入org.springframework.stereotype.Component;

@Component
@Aspect
パブリッククラスExecutionAop {


プログラムは異常があらわれた場合は、//、あなたがインターセプトする必要があり、印刷例外情報
@AfterThrowing
、(ポイントカット= "実行(* com.jt.service .. *。*(..))"を
投げます= "のThrowable")
公共ボイドafterThrow(ジョインポイントジョインポイント、のThrowableのThrowable){

<?> =クラスtargetClass joinPoint.getTarget()のgetClass();.
文字列methodNameの= joinPoint.getSignature()のgetName();.
クラスthrowClass <?> throwable.getClass =();
文字列あとでThrowable.getMessage MSG =();
のSystem.out.println( "ターゲット・オブジェクト・タイプがある:" + targetClass)
のSystem.out.println( "ターゲットメソッド:" methodNameの+)
のSystem.out .println( "例外のタイプ:" + throwClass)
のSystem.out.println( "例外情報:" + MSG);
}
}

おすすめ

転載: www.cnblogs.com/lizhiwei666/p/12037276.html