From 76bc7deb8ee542cac6130f47a1057408e6fa5e98 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 22 Feb 2023 17:30:20 +0100 Subject: [PATCH] Polish AOP chapter --- .../src/docs/asciidoc/core/core-aop.adoc | 77 +++++++++---------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/framework-docs/src/docs/asciidoc/core/core-aop.adoc b/framework-docs/src/docs/asciidoc/core/core-aop.adoc index a1722870a18..d3087e3be06 100644 --- a/framework-docs/src/docs/asciidoc/core/core-aop.adoc +++ b/framework-docs/src/docs/asciidoc/core/core-aop.adoc @@ -224,7 +224,7 @@ as needed. The @AspectJ support can be enabled with XML- or Java-style configuration. In either case, you also need to ensure that AspectJ's `aspectjweaver.jar` library is on the -classpath of your application (version 1.8 or later). This library is available in the +classpath of your application (version 1.9 or later). This library is available in the `lib` directory of an AspectJ distribution or from the Maven Central repository. @@ -274,10 +274,10 @@ import the tags in the `aop` namespace. With @AspectJ support enabled, any bean defined in your application context with a class that is an @AspectJ aspect (has the `@Aspect` annotation) is automatically detected by Spring and used to configure Spring AOP. The next two examples show the -minimal definition required for a not-very-useful aspect. +minimal steps required for a not-very-useful aspect. -The first of the two example shows a regular bean definition in the application -context that points to a bean class that has the `@Aspect` annotation: +The first of the two examples shows a regular bean definition in the application context +that points to a bean class that is annotated with `@Aspect`: [source,xml,indent=0,subs="verbatim,quotes"] ---- @@ -286,10 +286,10 @@ context that points to a bean class that has the `@Aspect` annotation: ---- -The second of the two examples shows the `NotVeryUsefulAspect` class definition, -which is annotated with the `org.aspectj.lang.annotation.Aspect` annotation; +The second of the two examples shows the `NotVeryUsefulAspect` class definition, which is +annotated with `@Aspect`: -[source,java,indent=0,subs="verbatim,quotes",role="primary",chomp="-packages"] +[source,java,indent=0,subs="verbatim,quotes",role="primary",chomp="-packages",fold="none"] .Java ---- package org.xyz; @@ -300,7 +300,7 @@ which is annotated with the `org.aspectj.lang.annotation.Aspect` annotation; public class NotVeryUsefulAspect { } ---- -[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary",chomp="-packages"] +[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary",chomp="-packages",fold="none"] .Kotlin ---- package org.xyz @@ -441,13 +441,7 @@ Spring AOP also supports an additional PCD named `bean`. This PCD lets you limit the matching of join points to a particular named Spring bean or to a set of named Spring beans (when using wildcards). The `bean` PCD has the following form: -[source,java,indent=0,subs="verbatim,quotes",role="primary"] -.Java ----- - bean(idOrNameOfBean) ----- -[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] -.Kotlin +[source,indent=0,subs="verbatim,quotes"] ---- bean(idOrNameOfBean) ---- @@ -515,7 +509,7 @@ of any public method. trading module. It is a best practice to build more complex pointcut expressions out of smaller named -components, as shown earlier. When referring to pointcuts by name, normal Java visibility +components, as shown above. When referring to pointcuts by name, normal Java visibility rules apply (you can see private pointcuts in the same type, protected pointcuts in the hierarchy, public pointcuts anywhere, and so on). Visibility does not affect pointcut matching. @@ -526,8 +520,8 @@ matching. When working with enterprise applications, developers often want to refer to modules of the application and particular sets of operations from within several aspects. We -recommend defining a `CommonPointcuts` aspect that captures common pointcut expressions -for this purpose. Such an aspect typically resembles the following example: +recommend defining a dedicated aspect that captures common pointcut expressions for this +purpose. Such an aspect typically resembles the following `CommonPointcuts` example: [source,java,indent=0,subs="verbatim",role="primary",chomp="-packages"] .Java @@ -659,9 +653,11 @@ for this purpose. Such an aspect typically resembles the following example: } ---- -You can refer to the pointcuts defined in such an aspect anywhere you need a -pointcut expression. For example, to make the service layer transactional, you could -write the following: +You can refer to the pointcuts defined in such an aspect anywhere you need a pointcut +expression by referencing the fully-qualified class name of the aspect combined with the +pointcut name. For example, to make the service layer transactional, you could write the +following which references the shared `com.xyz.myapp.CommonPointcuts.businessService()` +pointcut: [source,xml,indent=0,subs="verbatim,quotes"] ---- @@ -688,7 +684,7 @@ transaction elements are discussed in <