我们如何在 spring 中使用条件连接点
在我的要求中,如果方法名称是插入或者方法名称是更新或者方法名称是删除并且该方法应该正好有三个参数,则必须应用切点
这是我写的代码,
<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"/>
最佳答案
您需要一个复杂的切入点,它在单个表达式中包含所有逻辑。您正试图在表达式中引用其他切入点,但这是行不通的。
你需要做这样的事情:
<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
关于java - 在 spring 中使用条件连接点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8296132/