【问题标题】:Using @annotation in Spring AOP在 Spring AOP 中使用 @annotation
【发布时间】:2013-04-23 09:12:37
【问题描述】:

我正在使用带有 aspectj-autoproxy 的 Spring AOP。 我使用@Around 注解来拦截某些类和方法。

@Around(value = "@annotation(counter)")

这段代码应该拦截带有@Counter注解的方法。

我的问题是,这个定义是否强制扫描类路径中的所有类? 我之所以问,是因为我有一个巨大的项目,如果要扫描所有类路径,可能会遭受几分钟的加载时间。

如果答案是肯定的,我该如何禁用他的扫描?

【问题讨论】:

    标签: java spring aop spring-aop


    【解决方案1】:

    限制扫描使用:

    execution(* com.my.package..*.*(..)) && @annotation(counter)
    

    【讨论】:

      【解决方案2】:

      它只会扫描已定义的 Spring bean,因此不会扫描完整的类路径。此外,注释 @Counter 应指定为完全限定的类名,我认为“counter”不是正确的。 .

      【讨论】:

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