課程
/后端開發(fā)
/Java
/Spring入門篇
aop after-returning 和after的區(qū)別? 難道只是執(zhí)行順序的先后問題呢?大家都是在方法執(zhí)行后返回,區(qū)別在哪里呢
2015-04-25
源自:Spring入門篇 5-4
正在回答
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
? ?Object result;
? ?try {
? ? ? ?//@Before
? ? ? ?result = method.invoke(target, args);
? ? ? ?//@AfterReturning
? ? ? ?return result;
? ?} catch (InvocationTargetException e) {
? ? ? ?Throwable targetException = e.getTargetException();
? ? ? ?//@AfterThrowing
? ? ? ?throw targetException;
? ?} finally {
? ? ? ?//@After
? ?}
}
兄弟,到底哪個版本是對的???????
Ajayy
阿薩德
@Overridepublic Object invoke(Object proxy, Method method, Object[] args) throws Throwable { ? ?Object result; ? ?try { ? ? ? ?//@Before ? ? ? ?result = method.invoke(target, args); ? ? ? ?//@After ? ? ? ?return result; ? ?} catch (InvocationTargetException e) { ? ? ? ?Throwable targetException = e.getTargetException(); ? ? ? ?//@AfterThrowing ? ? ? ?throw targetException; ? ?} finally { ? ? ? ?//@AfterReturning ? ?}}
qq_慕婉清9181605
try{ try{ //@Before method.invoke(..); }finally{ //@After } //@AfterReturning }catch(){ //@AfterThrowing }
xchendevelop
binjoo
try { ????//??執(zhí)行前置通知; ???? ????//??執(zhí)行目標(biāo)方法; ???? ????//?執(zhí)行返回通知; } catche(Exception?e) { ????//?執(zhí)行異常通知; } finally { ????//?執(zhí)行后置通知; }
應(yīng)該是這樣的...
? ?//限定了返回值,可不寫,注意如果出現(xiàn)異常,則該設(shè)定不起作用,after returing對應(yīng)的方法不被執(zhí)行
?????<aop : after-returning ?returning = "retVar" ?method = "" ?pointcut-ref = "" />
????//after的執(zhí)行是在after returning之后,但無論方法是否正常結(jié)束, after通知都會被執(zhí)行
?????<aop : after ?method = "" ?pointcut = ?" " />
?after 對應(yīng)?target?執(zhí)行之后,?afterReturning??對應(yīng)在?target?處理后結(jié)果返回增強(qiáng)處理
可以看老師例子中after-returning和after對應(yīng)的輸出內(nèi)容進(jìn)行對比
J1J 回復(fù) 夢編猿
舉報(bào)
為您帶來IOC和AOP的基本概念及用法,為后續(xù)高級課程學(xué)習(xí)打下基礎(chǔ)
4 回答請問為什么這里 after是在after returning 之前?
4 回答after和afterrunning
2 回答after 和around的順序問題
1 回答前面講AOP的時(shí)候,用xml,after是在afterReturning之后,這里什么變之前了?
1 回答為什么上一節(jié)是先afterReturning再after,這一節(jié)變成了先after再afterReturning
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2020-12-07
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
? ?Object result;
? ?try {
? ? ? ?//@Before
? ? ? ?result = method.invoke(target, args);
? ? ? ?//@AfterReturning
? ? ? ?return result;
? ?} catch (InvocationTargetException e) {
? ? ? ?Throwable targetException = e.getTargetException();
? ? ? ?//@AfterThrowing
? ? ? ?throw targetException;
? ?} finally {
? ? ? ?//@After
? ?}
}
2020-09-27
兄弟,到底哪個版本是對的???????
2017-07-25
2017-05-02
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
? ?Object result;
? ?try {
? ? ? ?//@Before
? ? ? ?result = method.invoke(target, args);
? ? ? ?//@After
? ? ? ?return result;
? ?} catch (InvocationTargetException e) {
? ? ? ?Throwable targetException = e.getTargetException();
? ? ? ?//@AfterThrowing
? ? ? ?throw targetException;
? ?} finally {
? ? ? ?//@AfterReturning
? ?}
}
2016-12-23
2016-08-19
應(yīng)該是這樣的...
2016-07-27
? ?//限定了返回值,可不寫,注意如果出現(xiàn)異常,則該設(shè)定不起作用,after returing對應(yīng)的方法不被執(zhí)行
?????<aop : after-returning ?returning = "retVar" ?method = "" ?pointcut-ref = "" />
????//after的執(zhí)行是在after returning之后,但無論方法是否正常結(jié)束, after通知都會被執(zhí)行
?????<aop : after ?method = "" ?pointcut = ?" " />
2015-04-27
?after 對應(yīng)?target?執(zhí)行之后,?afterReturning??對應(yīng)在?target?處理后結(jié)果返回增強(qiáng)處理
可以看老師例子中after-returning和after對應(yīng)的輸出內(nèi)容進(jìn)行對比