Results 1 to 4 of 4

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

  1. #1
    Join Date
    Sep 2012
    Posts
    4

    Default 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. #2
    Join Date
    Sep 2012
    Location
    Czech Republic
    Posts
    39

    Default

    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.

  3. #3
    Join Date
    Sep 2012
    Posts
    4

    Default

    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

  4. #4
    Join Date
    Sep 2012
    Posts
    4

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •