Skip to content

Commit

Permalink
Polish AOP chapter in reference manual
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jun 8, 2020
1 parent 9e1121f commit 0b760c1
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/docs/asciidoc/core/core-aop.adoc
Expand Up @@ -1637,16 +1637,16 @@ 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).

When two pieces of advice defined in different aspects both need to run at the same
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.

Expand Down Expand Up @@ -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
(<<aop-ataspectj>>) for an understanding of writing pointcut expressions and the binding
of advice parameters.

Expand Down Expand Up @@ -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 <aop:aspect> element, and reference the backing bean
You can declare an aspect by using the `<aop:aspect>` element, and reference the backing bean
by using the `ref` attribute, as the following example shows:

[source,xml,indent=0,subs="verbatim,quotes"]
Expand Down Expand Up @@ -2069,7 +2069,7 @@ collects the `this` object as the join point context and passes it to the advice
<aop:aspect id="myAspect" ref="aBean">
<aop:pointcut id="businessService"
expression="execution(* com.xyz.myapp.service.*.*(..)) && this(service)"/>
expression="execution(* com.xyz.myapp.service.*.*(..)) &amp;&amp; this(service)"/>
<aop:before pointcut-ref="businessService" method="monitor"/>
Expand Down Expand Up @@ -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, `+&amp;&amp;+` is awkward within an XML
document, so you can use the `and`, `or`, and `not` keywords in place of `+&amp;&amp;+`,
`||`, and `!`, respectively. For example, the previous pointcut can be better written as
follows:

[source,xml,indent=0,subs="verbatim"]
----
Expand Down Expand Up @@ -2136,7 +2137,7 @@ exactly the same semantics.
==== Before Advice

Before advice runs before a matched method execution. It is declared inside an
`<aop:aspect>` by using the <aop:before> element, as the following example shows:
`<aop:aspect>` by using the `<aop:before>` element, as the following example shows:

[source,xml,indent=0,subs="verbatim,quotes"]
----
Expand Down Expand Up @@ -2198,8 +2199,8 @@ shows how to declare it:
</aop:aspect>
----

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"]
Expand Down Expand Up @@ -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 `<aop:aspect>` by using the after-throwing element,
exception. It is declared inside an `<aop:aspect>` by using the `after-throwing` element,
as the following example shows:

[source,xml,indent=0,subs="verbatim,quotes"]
Expand All @@ -2252,8 +2253,8 @@ as the following example shows:
</aop:aspect>
----

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"]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <<aop-ataspectj-advice-ordering>>. 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 <<aop-ataspectj-advice-ordering>>. The precedence
between aspects is determined via the `order` attribute in the `<aop:aspect>` element or
by either adding the `@Order` annotation to the bean that backs the aspect or by having
the bean implement the `Ordered` interface.



Expand Down

0 comments on commit 0b760c1

Please sign in to comment.