aop:config内的标签书写顺序是否有要求?

题目描述

使用Spring AOP时发现在<aop:config>定义<aop:pointcut>和<aop:aspect>顺序不正确会造成报错。

题目来源及相关代码

下面xml中使用到的bean均已注册。
如下代码写不报错:

<aop:config>

<aop:pointcut id="performence" expression="execution(* com.Leslie.pojo.performer.singer.perform())

and bean(duke)"/>

<aop:pointcut id="think" expression="execution(* com.Leslie.pojo.Volunteer.think(String))

and args(thought)

and bean(hank)"/>

<aop:aspect ref="audience">

<aop:before method="takeSeats" pointcut-ref="performence"/>

<aop:before method="turnOffPhone" pointcut-ref="performence"/>

<aop:after-returning method="applaud" pointcut-ref="performence"/>

<aop:after-throwing method="demanRefund" pointcut-ref="performence"/>

</aop:aspect>

<aop:aspect ref="james">

<aop:before method="guessThought" pointcut-ref="think" arg-names="thought"/>

</aop:aspect>

</aop:config>

如下代码写报错:

<aop:config>

<aop:pointcut id="performence" expression="execution(* com.Leslie.pojo.performer.singer.perform())

and bean(duke)"/>

<aop:aspect ref="audience">

<aop:before method="takeSeats" pointcut-ref="performence"/>

<aop:before method="turnOffPhone" pointcut-ref="performence"/>

<aop:after-returning method="applaud" pointcut-ref="performence"/>

<aop:after-throwing method="demanRefund" pointcut-ref="performence"/>

</aop:aspect>

<aop:pointcut id="think" expression="execution(* com.Leslie.pojo.Volunteer.think(String))

and args(thought)

and bean(hank)"/>

<aop:aspect ref="james">

<aop:before method="guessThought" pointcut-ref="think" arg-names="thought"/>

</aop:aspect>

</aop:config>

报错信息如下图:

是不是定义顺序的问题呢?Spring AOP对标签定义顺序有什么要求呢?

以上是 aop:config内的标签书写顺序是否有要求? 的全部内容, 来源链接: utcz.com/p/944642.html

回到顶部