sahil-ag opened SPR-17285 and commented

@within point-cut doesn't seem to be working when we extend a class and annotate the extended class. This also doesn't seem to take into account the @inherited annotation

Sample project: https://github.com/sahil-ag/Spring-AOP-Sample

Project works when we use @target but should also be working for @within


No further details from SPR-17285

Comment From: spring-projects-issues

sahil-ag commented

Hi Is there any update here?

Comment From: spring-projects-issues

Andy Clement commented

Sorry, haven't had a chance, but I will take a look at the project you attached (thanks for that!) as soon as I can.

Comment From: aclement

Ok, @within, like within, is about lexical scope and what is declared at compile/weave time. @target, like target, is about dynamic scope and what is happening at runtime.

For the 3 testcases: If the pointcuts are ( A ): @within(SampleAnnotation) || @annotation(SampleAnnotation) ( B ): @target(SampleAnnotation) || @annotation(SampleAnnotation)

  • testAnnotedMethod - Both A and B match because @annotation(SampleAnnotation) matches on the method in BaseMethod class.
  • testAnnotatedBeanExtended - B matches, A does not match. The method getTestName() is declared in BaseClass and neither that method or that type is annotated, so if that is the static state 'as declared' and so neither of these pointcut components are true in A. Now B matches dynamically because the runtime type on which the getTestName() is being called is a BaseClassExtended which is annotated.
  • testAnnotatedBean - Neither A nor B match. BaseClass nor getTestName() are annotated.

So I am saying it is working as designed. Does that help?

Comment From: sahil-ag

Correct me if I am wrong but shouldn't @within consider all the functions which are available to the class at compile time and based on how inheritance works, that function will hence be available in the lexical scope?

Comment From: hurelhuyag

@annotation not working. I tried whole day to make it work. Is anyone has workaround it?

Comment From: sbrannen

@annotation not working. I tried whole day to make it work. Is anyone has workaround it?

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.