【问题标题】:Using conditional join points in spring在春季使用条件连接点
【发布时间】:2011-11-29 00:04:17
【问题描述】:

我们如何在spring中使用条件连接点

在我的要求中,如果 方法名称是 insert 或方法名称是 update 或方法名称是 delete 并且该方法应该有三个参数,则必须应用切入点

这是我写的代码,

  <aop:config>
    <aop:aspect  ref="auditAOP">
        <aop:pointcut id="insert" expression="execution(* .IbatisDAOSupportImpl.insert(*,*,*))" />
        <aop:pointcut id="delete" expression="execution(* IbatisDAOSupportImpl.delete(*,*,*))" />
        <aop:pointcut id="update" expression="execution(* IbatisDAOSupportImpl.update(*,*,*))" />
        <aop:pointcut id="auditInsertUpdateOrDelete" expression="insert || delete || update"/>
        <aop:after method="afterInsertUpdateOrDelete" pointcut-ref="auditInsertUpdateOrDelete"/>
    </aop:aspect>

</aop:config>

下面这行有问题;我收到一个错误,说表达式格式不正确。

    <aop:pointcut id="auditInsertUpdateOrDelete" expression="insert || delete || update"/>

【问题讨论】:

    标签: java spring aop pointcuts aspect


    【解决方案1】:

    您需要一个复杂的切入点,它在一个表达式中包含所有逻辑。你试图在你的表达式中引用你的其他切入点,这是行不通的。

    你需要做这样的事情:

    <aop:config>
      <aop:aspect  ref="auditAOP">
        <aop:pointcut id="auditInsertUpdateOrDelete" expression="within(*.IbatisDAOSupportImpl)
                         and (execution( * insert*(..)) or 
                         execution( * delete*(..))  or 
                         execution( * update*(..)))"/>
        <aop:after method="afterInsertUpdateOrDelete" pointcut-ref="auditInsertUpdateOrDelete"/>
      </aop:aspect>
    </aop:config>
    

    这是构建复杂表达式的一个很好的参考: http://forum.springsource.org/showthread.php?37596-complex-pointcut-expressions

    【讨论】:

      猜你喜欢
      • 2015-06-26
      • 1970-01-01
      • 2021-07-31
      • 2012-03-04
      • 1970-01-01
      • 2011-08-27
      • 2016-11-01
      • 2021-02-15
      • 2023-03-27
      相关资源
      最近更新 更多