关于Spring使用XML配置AOP时pointcut位置的一个小问题

 <aop:config>
        <aop:pointcut id="xmllog" expression="execution(* com.xhu.service.MyService.*(..))"/>
        <aop:pointcut id="xmlafter" expression="execution(* com.xhu.service.MyService.testAfterXML(..))"/>
        <aop:aspect id="aspectxml2" ref="aopxml2">

            <aop:before method="LogBeforeXML" pointcut-ref="xmllog"/>
            <aop:after method="LogAfterXML" pointcut-ref="xmlafter"></aop:after>

        </aop:aspect>
    </aop:config>

问题描述:今天学习spring中使用XML配置AOP时遇到了点问题,配置多个切入点POINTCUT时,发现只能配置一个。

查阅资料才发现POINTCUT在XML文件中配置的位置有问题。

要配置多个point时格式如(标签pointcut在标签aspect之外):

 <aop:config>
        <aop:pointcut />
        <aop:pointcut />

<aop:aspect> </aop:aspect> </aop:config>

当pointcut标签在aspect标签中时,只能配置一个pointcut,第二个会失效。格式如:

 <aop:config>
        <aop:aspect>
<aop:pointcut/> </aop:aspect> </aop:config>

 

posted @ 2020-05-21 22:36  Unlimited_Rain  阅读(666)  评论(0)    收藏  举报