Announcement Announcement Module
Collapse
No announcement yet.
How to find if the current joinPoint in an advices matches a joinpoint expression Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to find if the current joinPoint in an advices matches a joinpoint expression

    What i'd like to do is when an aspect is invoked based on the pointcut being matched, perform several tasks, then if the aspect is being invoked because of a select few of these pointcuts being matched, perform an additional task.

    Something like this
    Code:
    public boolean matches(ProceedingJoinPoint joinPoint, Pointcut pointcut);
    i've found the method AspectJExpressionPointcut.matches(Method, Class<?>) that seems to get close however it seems to falsely return true when the pointcut expression is a bean pointcut and this is testing a method and class that have nothing to do with it
    Code:
    <aop:pointcut id="beanPointcut"	expression="bean(someBean)"/>
    So, to rephrase my question, how can you tell which pointcut is the one that matched causing the current aspect to be invoked?

    Thanks
    Jeff

  • #2
    A bean is a factory definition for making class instances. Once an instance is created, it has no reference to its bean definition. Therefore you cannot do pointcut matching on bean names at runtime. The bean name pointcut matching only applies in the time the bean instance is created.

    Javadoc on Spring class BeanNameContextMatcher describes the behavior (always returning true) that you observe.

    If it is possible, i would suggest to do the common tasks in one advice and the additional task in another one.

    Comment


    • #3
      I thought about that. I was trying to put it all in one place but it sounds like your suggestion may be the best alternative

      Comment


      • #4
        I think somewhere along the line, i thought i'd be able to get information about the pointcut that was hit (even simply its id) out of the invocation, but it seems this cannot be done, regardless of the expression that was hit, no information about the pointcut appears to be accessible.

        Comment

        Working...
        X