亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么我的輸入結果和視頻里的不一樣?(Around advice)

我的輸出結果(代碼是一樣的):

MoocAspect before.

MoocAspect aroud 1.

AspectBiz biz.

MoocAspect afterReturning.

MoocAspect after.

MoocAspect aroud 2.

正在回答

5 回答

因為是隨機的,你可以用order設置順序,詳見spring文檔。文檔中的finally僅僅表示一定會被執行,并不代表最后被執行

0 回復 有任何疑惑可以回復我~

public void before()

{

System.out.println("MoocAspect before.");

}

public void afterReturning()

{

System.out.println("MoocAspect afterReturning.");

}

public void afterThrowing()

{

System.out.println("MoocAspect afterThrowing.");

}

public void after()

{

System.out.println("MoocAspect after.");

}

public Object around(ProceedingJoinPoint pjp)

{

Object obj = null;

try

{

System.out.println("MoocAspect aroud 1.");

obj = pjp.proceed();

System.out.println("MoocAspect aroud 2.");

} catch (Throwable e)

{

e.printStackTrace();

}

return obj;

}

0 回復 有任何疑惑可以回復我~

你定義的順序和結果是一樣的么?你看一下你的定義順序,都是按定義的順序執行的。

0 回復 有任何疑惑可以回復我~
#1

砂鍋飯嘍 提問者

定義順序是指moocAspect這個類中的順序嗎?這個類中方法的順序和視頻中是一樣的
2015-03-04 回復 有任何疑惑可以回復我~
#2

Coda 回復 砂鍋飯嘍 提問者

是的,就是moocAspect
2015-03-04 回復 有任何疑惑可以回復我~
#3

砂鍋飯嘍 提問者 回復 Coda

moocAspect中代碼已貼出,順序為before,afterReturning,afterThrowing,after,around
2015-03-04 回復 有任何疑惑可以回復我~

配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>

<beans

xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:aop="http://www.springframework.org/schema/aop"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/aop

? ? http://www.springframework.org/schema/aop/spring-aop-3.1.xsd

">

<bean id="moocAspect" class="com.yxq.aop.MoocAspect"></bean>

<bean id="aspectBiz" class="com.yxq.aop.AspectBiz"></bean>

<aop:config>

? <aop:aspect id="moocAspectAOP" ref="moocAspect">

? ? ?<aop:pointcut expression="execution(* com.yxq.aop.*Biz.*(..))" id="moocPointcut"/>

? ? ?<aop:before method="before" pointcut-ref="moocPointcut"/>

? ? ?<aop:after-returning method="afterReturning" pointcut-ref="moocPointcut"/>

? ? ?<aop:after-throwing method="afterThrowing" pointcut-ref="moocPointcut"/>

? ? ?<aop:after method="after" pointcut-ref="moocPointcut"/>

? ? ?<aop:around method="around" pointcut-ref="moocPointcut"/>

? </aop:aspect>

</aop:config>

</beans>

0 回復 有任何疑惑可以回復我~

你的配置文件也要和視頻的一樣

0 回復 有任何疑惑可以回復我~
#1

砂鍋飯嘍 提問者

我覺得我的配置文件和視頻上的應該是一樣的,除了Spring版本不一致,配置文件已貼出
2015-03-04 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么我的輸入結果和視頻里的不一樣?(Around advice)

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號