在春季切入点使用注释

时间:2011-11-29 13:44:33

标签: java annotations aop spring-aop pointcut

我正在使用注释来指示需要将建议应用于该方法。

我在名为IMaintenanceDAOSupport

的界面中有两种方法
@AuditLogging
void insert(M domainobject, IntResponse response, String statementName);

@AuditLogging
int delete(M domainobject, IntResponse response, String statementName);

我们如何为要应用的方面配置xml?

目前我有

<aop:config>
  <aop:aspect  ref="auditAOP">
    <aop:pointcut id="im-insert"  
                  expression="within(IMaintenanceDAOSupport)and execution(@annotation(AuditLogging))"/>
    <aop:after method="afterInsertUpdateOrDelete" pointcut-ref="im-insert"/>
  </aop:aspect>
</aop:config>

它给出了编译错误;你看到配置中有任何错误吗?

2 个答案:

答案 0 :(得分:0)

您应该使用&#34;&amp;&amp;&#34; 而不是&#34;和&#34;组合切点表达。

切入点表达式可以使用&#39;&amp;&amp;&#39;,&#39; ||&#39;和&#39;!&#39;。

答案 1 :(得分:0)

@annotation不需要execution()块。尝试:

within(IMaintenanceDAOSupport) && @annotation(AuditLogging)