From 0b760c15eae79cfe3b9529b1de7414db315f959f Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 8 Jun 2020 16:51:15 +0200 Subject: [PATCH] Polish AOP chapter in reference manual --- src/docs/asciidoc/core/core-aop.adoc | 44 +++++++++++++++------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/docs/asciidoc/core/core-aop.adoc b/src/docs/asciidoc/core/core-aop.adoc index 248ca241385b..a2e30c53c3fb 100644 --- a/src/docs/asciidoc/core/core-aop.adoc +++ b/src/docs/asciidoc/core/core-aop.adoc @@ -1637,8 +1637,8 @@ In many cases, you do this binding anyway (as in the preceding example). What happens when multiple pieces of advice all want to run at the same join point? Spring AOP follows the same precedence rules as AspectJ to determine the order of advice -execution. The highest precedence advice runs first "`on the way in`" (so, given two pieces -of before advice, the one with highest precedence runs first). "`On the way out`" from a +execution. The highest precedence advice runs first "on the way in" (so, given two pieces +of before advice, the one with highest precedence runs first). "On the way out" from a join point, the highest precedence advice runs last (so, given two pieces of after advice, the one with the highest precedence will run second). @@ -1646,7 +1646,7 @@ When two pieces of advice defined in different aspects both need to run at the s join point, unless you specify otherwise, the order of execution is undefined. You can control the order of execution by specifying precedence. This is done in the normal Spring way by either implementing the `org.springframework.core.Ordered` interface in -the aspect class or annotating it with the `Order` annotation. Given two aspects, the +the aspect class or annotating it with the `@Order` annotation. Given two aspects, the aspect returning the lower value from `Ordered.getValue()` (or the annotation value) has the higher precedence. @@ -1950,9 +1950,9 @@ expression so that only `@Idempotent` operations match, as follows: == Schema-based AOP Support If you prefer an XML-based format, Spring also offers support for defining aspects -using the new `aop` namespace tags. The exact same pointcut expressions and advice kinds +using the `aop` namespace tags. The exact same pointcut expressions and advice kinds as when using the @AspectJ style are supported. Hence, in this section we focus on -the new syntax and refer the reader to the discussion in the previous section +that syntax and refer the reader to the discussion in the previous section (<>) for an understanding of writing pointcut expressions and the binding of advice parameters. @@ -1982,7 +1982,7 @@ When you use the schema support, an aspect is a regular Java object defined as a your Spring application context. The state and behavior are captured in the fields and methods of the object, and the pointcut and advice information are captured in the XML. -You can declare an aspect by using the element, and reference the backing bean +You can declare an aspect by using the `` element, and reference the backing bean by using the `ref` attribute, as the following example shows: [source,xml,indent=0,subs="verbatim,quotes"] @@ -2069,7 +2069,7 @@ collects the `this` object as the join point context and passes it to the advice + expression="execution(* com.xyz.myapp.service.*.*(..)) && this(service)"/> @@ -2098,9 +2098,10 @@ parameters of the matching names, as follows: } ---- -When combining pointcut sub-expressions, `&&` is awkward within an XML document, so -you can use the `and`, `or`, and `not` keywords in place of `&&`, `||`, and `!`, -respectively. For example, the previous pointcut can be better written as follows: +When combining pointcut sub-expressions, `+&&+` is awkward within an XML +document, so you can use the `and`, `or`, and `not` keywords in place of `+&&+`, +`||`, and `!`, respectively. For example, the previous pointcut can be better written as +follows: [source,xml,indent=0,subs="verbatim"] ---- @@ -2136,7 +2137,7 @@ exactly the same semantics. ==== Before Advice Before advice runs before a matched method execution. It is declared inside an -`` by using the element, as the following example shows: +`` by using the `` element, as the following example shows: [source,xml,indent=0,subs="verbatim,quotes"] ---- @@ -2198,8 +2199,8 @@ shows how to declare it: ---- -As in the @AspectJ style, you can get the return value within the -advice body. To do so, use the returning attribute to specify the name of the parameter to which +As in the @AspectJ style, you can get the return value within the advice body. +To do so, use the `returning` attribute to specify the name of the parameter to which the return value should be passed, as the following example shows: [source,xml,indent=0,subs="verbatim,quotes"] @@ -2236,7 +2237,7 @@ example, you can declare the method signature as follows: ==== After Throwing Advice After throwing advice executes when a matched method execution exits by throwing an -exception. It is declared inside an `` by using the after-throwing element, +exception. It is declared inside an `` by using the `after-throwing` element, as the following example shows: [source,xml,indent=0,subs="verbatim,quotes"] @@ -2252,8 +2253,8 @@ as the following example shows: ---- -As in the @AspectJ style, you can get the thrown exception within -the advice body. To do so, use the throwing attribute to specify the name of the parameter to +As in the @AspectJ style, you can get the thrown exception within the advice body. +To do so, use the `throwing` attribute to specify the name of the parameter to which the exception should be passed as the following example shows: [source,xml,indent=0,subs="verbatim,quotes"] @@ -2309,7 +2310,7 @@ by using the `after` element, as the following example shows: [[aop-schema-advice-around]] ==== Around Advice -The last kind of advice is around advice. Around advice runs "`around`" a matched method +The last kind of advice is around advice. Around advice runs "around" a matched method execution. It has the opportunity to do work both before and after the method executes and to determine when, how, and even if the method actually gets to execute at all. Around advice is often used to share state before and after a method @@ -2548,10 +2549,11 @@ ms % Task name [[aop-ordering]] ==== Advice Ordering -When multiple advice needs to execute at the same join point (executing method) the -ordering rules are as described in <>. The precedence -between aspects is determined by either adding the `Order` annotation to the bean -that backs the aspect or by having the bean implement the `Ordered` interface. +When multiple pieces of advice need to execute at the same join point (executing method) +the ordering rules are as described in <>. The precedence +between aspects is determined via the `order` attribute in the `` element or +by either adding the `@Order` annotation to the bean that backs the aspect or by having +the bean implement the `Ordered` interface.