【问题标题】:@AspectJ pointcut for execute methods of a package@AspectJ 用于执行包的方法的切入点
【发布时间】:2011-12-09 19:40:06
【问题描述】:

我想在特定的包中执行一个执行方法。

这可能是什么切入点?

注意:我使用的是@AspectJ 风格的 Spring AOP。

【问题讨论】:

  • 请详细一点。所以...您有一个要调用的方法,称为 execute(),您想从哪里执行它?
  • 如果我理解正确,如果我们谈论执行切入点,您需要以下执行(* com.company..*(..))
  • thanx SirVaulterScoff 这可以用于包中的每个方法,但我想执行一个名为 abc 的特定方法,那么我需要在哪里提供它?
  • 考虑到 spring-aop 你应该有这样的东西: 显然你应该有一个名为 myAdvice 的 spring bean,它实现了 org.aopalliance.intercept.MethodInterceptor

标签: java aop aspectj spring-aop


【解决方案1】:

看看这里http://www.eclipse.org/aspectj/doc/released/adk15notebook/annotations-pointcuts-and-advice.html

@(org.xyz..*) 匹配任何带有注释的元素 与类型模式(org.xyz..*) 匹配的类型的注释。其他 单词,带有注释的注释元素,该注释在 org.xyz 包或子包。 (括号是必需的 这个例子)。

所以你应该有以下 aop 配置:

<aop:config>
 <aop:advisor advice-ref="myAdvice" pointcut="execution(* com.mycompany..*(..))" order="1"/> 
</aop:config>

这个建议的匹配 bean

<bean id="myadvice" class="com.mycompany.MyIntercetpor"/>

拦截器应该实现 org.aopalliance.intercept.MethodInterceptor

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2013-02-12
    相关资源
    最近更新 更多