【问题标题】:Spring AOP only method with annotation带有注解的 Spring AOP 唯一方法
【发布时间】:2017-01-04 20:56:48
【问题描述】:

我有这个 AOP 可以在我的所有应用程序方法上运行,但我希望它只在带有 ProfileExecution 注释的方法上运行, 我该如何使用这个 xml

<bean id="profiler" class="com.mytest.ProfilerExecution" />


<aop:config>
    <aop:aspect ref="profiler">

        <aop:pointcut id="serviceMethod" 
            expression="execution(public * *(..))" />
            <aop:around pointcut-ref="serviceMethod" method="profile"/>
    </aop:aspect>
</aop:config>

谢谢

【问题讨论】:

    标签: spring-aop spring-annotations


    【解决方案1】:

    使用以下切入点表达式@annotation(com.abc.xyz.ProfileExecution)AND 操作来过滤方法。

    所以最终的 xml 应该如下所示

    <aop:config>
        <aop:aspect ref="profiler">
            <aop:pointcut id="serviceMethod" 
                expression="execution(public * *(..)) and @annotation(com.abc.xyz.ProfileExecution)" />
            <aop:around pointcut-ref="serviceMethod" method="profile"/>
        </aop:aspect>
    </aop:config>
    

    确保在表达式中包含注释的完全限定名称,否则它将不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-30
      • 2011-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多