Domanda

How do we use conditional join points in spring

In my requirement, the point cut has to be applied if the method name is insert OR the method name is update OR method name is delete AND the method should have exactly three arguments

This was the code I wrote,

  <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>

There is something wrong with the below line; I get an error saying the expression is not well formed.

    <aop:pointcut id="auditInsertUpdateOrDelete" expression="insert || delete || update"/>
È stato utile?

Soluzione

You need a complex pointcut which contains all the logic in a single expression. You are trying to refer to your other pointcuts within your expression, which just doesn't work.

You need to do something like this:

<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>

Here is a good reference for building complex expressions: http://forum.springsource.org/showthread.php?37596-complex-pointcut-expressions

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top