【问题标题】:using annotations in spring pointcut在 spring 切入点中使用注释
【发布时间】:2013-02-15 23:45:50
【问题描述】:

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

我在一个名为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>

编译错误;您看到配置中有什么错误吗?

【问题讨论】:

  • “出现编译错误”你看到了什么错误?
  • java.lang.IllegalArgumentException:切入点格式不正确:在字符位置 139 处需要“名称模式”

标签: java annotations aop spring-aop pointcut


【解决方案1】:

您应该使用 “&&” 而不是“and”来组合切入点表达式。

切入点表达式可以使用 '&&'、'||' 组合和“!”。

【讨论】:

  • 我认为这不是问题所在。尝试了您的建议,但没有奏效。
【解决方案2】:

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

within(IMaintenanceDAOSupport) && @annotation(AuditLogging)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    相关资源
    最近更新 更多