Announcement Announcement Module
Collapse
No announcement yet.
Pointcut expression problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

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

    Code:
        <aop:pointcut 
          id="testPointcut" 
          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:

    Code:
    <aop:pointcut 
          id="testPointcut" 
          expression="execution(* *.load(..)) and !within(test.Second)"/>

    Comment

    Working...
    X