Announcement Announcement Module
No announcement yet.
Pointcut expression problem Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pointcut expression problem

    Dear Spring Framework Support Forums Audience,

    I'm working with Spring AOP and have some problems creating correct pointcut expression to satisfy my goals. Please advice me what I'm doing wrong or maybe current version of Spring AOP doesn't provide such ability. Thanks in advance.

    Here is a context of the problem:

    I have public abstract class Base with public method load() which will be adviced. This method is not abstract.

    Now I have three classes First, Second, Third which extend this Base class. Class First overrides load() method and the others (Second and Third) doesn't.

    The goal is to apply my created advice AdviceDummy only for First and Third classes not for Second.

    This spring-test.xml provides me with execution of advice for each of classes when executing load() method on their instances:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="" xmlns:xsi="" xmlns:aop=""
      <aop:config proxy-target-class="true">
        <aop:pointcut id="testPointcut" expression="execution(* *.load(..))"/>
        <aop:aspect ref="testAdvice">
          <aop:around method="aroundLoad" pointcut-ref="testPointcut"/>
      <bean id="testAdvice" class="test.AdviceDummy" />
      <bean id="first" class="test.First"/>
      <bean id="second" class="test.Second"/>
      <bean id="third" class="test.Third"/>
    One way I've found is to override this load() method in Third class and then declaring this pointcut:

          expression="execution(* test.First.load(..)) or execution(* test.Third.load(..))"/>
    But this approach is not good in my example because I want a configuration which must not know if the class to be advised implements the load() method itself or uses the one from a superclass.

    Thanks for you help.

  • #2
    I've found the solution, you can use this in such cases:

          expression="execution(* *.load(..)) and !within(test.Second)"/>