In the Spring AOP manual, the sample code falsely reads in both Java and Kotlin examples as follows:

@Aspect("perthis(com.xyz.myapp.CommonPointcuts.businessService())")

But inside perthis must be a valid pointcut, not just a method name, as I explained in this StackOverflow answer.

Thus, the example code should be changed to something like:

@Aspect("perthis(execution(* com.xyz.myapp.CommonPointcuts.businessService()))")

@sbrannen, maybe you are the right person to review and merge this issue.

Comment From: sbrannen

Hi @kriegaex,

In the Spring AOP manual, the sample code falsely reads in both Java and Kotlin examples as follows:

java @Aspect("perthis(com.xyz.myapp.CommonPointcuts.businessService())")

It turns out that the examples are correct as-is. CommonPointcuts defines shared pointcuts as explained earlier in the documentation in the Sharing Common Pointcut Definitions section.

To ensure that this works as expected, I pushed some changes to the tests in commit b437b7be3463dc60e3fa49a648d85743182d6f74.

However, I can understand the confusion if one jumps to a particular example in the AOP chapter without having read the Sharing Common Pointcut Definitions section. So we may possibly reconsider our use of shared pointcuts in subsequent examples or possibly cross reference the Sharing Common Pointcut Definitions section. See #30003.

In light of that, I am closing this PR.

As a side note, your PR made me realize that our package statements are no longer displayed for those AOP/AspectJ examples and that inspired me to create #30001.

So thanks for bringing that to my attention! 👍

Comment From: kriegaex

@sbrannen, I am sorry to have missed that. I even think, it happened for the second time within two or so years when trying to help someone on Stack Overflow. Actually, in my own experience it is a rather rare case to refer to pointcuts defined in a class other than the current aspect or one of its parents and requiring a fully qualified pointcut method name, even though perfectly fine as a development practice. Unfortunately, it makes reading the manual section in question misleading. When just looking for how to use this() and target() without also having read the section about sharing pointcuts the very same day, it is utterly non-intuitive, because the reader is lacking context, despite your best efforts to name the shared pointcuts class CommonPointcuts, which did not really register in my mind when reading this manual section in isolation.

I am not an AOP newbie. In fact, I am the current maintainer of AspectJ and still missed that. Chances are that other users will miss it, too. Would you mind me modifying the PR to mention the fact that you are referring to a pointcut defined in another class here, and maybe also provide a brief example of an inline pointcut?


Update: Having followed the links to the newly created issues, I am quite pleased with the fact that you agree that as-is the examples are counter-intuitive and you are planning to do something about it, especially with regard to the extensive use of shared pointcuts in introductory sample code. I really think that inline pointcuts should be used there, or maybe code comments mentioning the fact that you are referring to shared pointcuts would suffice. If you would like me to contribute in order to expedite an update, please let me know.