spring AOPにおける配置
aop:config配置
一つのアプリは複数の「aop:config」を含み、一つの「aop:config」は順にpointcut、advisor、aspectを配置します。
aspectを切り、aop:aspectで声明します。例えば:
ポイントpointcutを切り込み、aop:pointcutで宣言します。例えば、
before通知はaop:aspectでaop:beforeで宣言します。マッチングの方法が実行される前に入力します。
一つのアプリは複数の「aop:config」を含み、一つの「aop:config」は順にpointcut、advisor、aspectを配置します。
aspectを切り、aop:aspectで声明します。例えば:
<aop:config>
<aop:aspect id = "aspect" ref = "myBean">
....
aop:aspect>
aop:config>
id = "myBean" class = "...">
....
切り込みポイントはうどんの中で声明することができます。また、aop:configの中で声明することもできます。ポイントpointcutを切り込み、aop:pointcutで宣言します。例えば、
<aop:config>
<aop:pointcut id = "businessService" expression = "execution(* com.lzr.service.businessService.*.* (..))" />
aop:config>
adviceに通知するbefore通知はaop:aspectでaop:beforeで宣言します。マッチングの方法が実行される前に入力します。
id = "beforeExample" ref = "myBean">
before pointcut = "execution(* com.lzr.dao.*.*(..))" method = "doAcessCheck" />
....
戻るとafter return adviceに通知し、マッチングの方法が完全に実行された後に実行します。例えば、id = "afterReturningExample" ref = "myBean">
after-returning poingcut-ref = "dataAccessOperation" method = "doAcessCheck" />
....
方法dataAccess OperationにイメージValがあれば、こう書くことができます。id = "afterReturningExample" ref = "myBean">
after-returning poingcut-ref = "dataAccessOperation" returning = "reVal" method = "doAcessCheck" />
....
異常を投げたらafter throwing adviceに通知し、マッチングの方法で異常終了をスローした時に実行します。id = "afterThrowingExample" ref = "myBean">
after-throwing poingcut-ref = "dataAccessOperation" method = "doAcessCheck" />
....
throwing属性を使用して、異常な名前を指定します。id = "afterThrowingExample" ref = "myBean">
after-throwing poingcut-ref = "dataAccessOperation" throwing = "dataAcessEx" method = "doAcessCheck" />
....
アフターサービスに連絡します。id = "afterFinallyExample" ref = "myBean">
after pointcut-ref = "dataAccessOperation" method="doReleaseLock"/>
....
周囲にアラウンドアドバンスを通知します。id = "around advice" ref = "myBean">
around pointcut-ref = "businessService" method = "doBasicProfiling">
....
....