Skip to content

Commit 173084f

Browse files
committed
Polish Spring AOP documentation
1 parent 6544698 commit 173084f

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

framework-docs/modules/ROOT/pages/core/aop-api/advice.adoc

+18-21
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ arbitrary advice types. This section describes the basic concepts and standard a
3333
[[aop-api-advice-around]]
3434
=== Interception Around Advice
3535

36-
The most fundamental advice type in Spring is interception around advice.
36+
The most fundamental advice type in Spring is _interception around advice_.
3737

3838
Spring is compliant with the AOP `Alliance` interface for around advice that uses method
3939
interception. Classes that implement `MethodInterceptor` and that implement around advice should also implement the
@@ -49,8 +49,8 @@ following interface:
4949

5050
The `MethodInvocation` argument to the `invoke()` method exposes the method being
5151
invoked, the target join point, the AOP proxy, and the arguments to the method. The
52-
`invoke()` method should return the invocation's result: the return value of the join
53-
point.
52+
`invoke()` method should return the invocation's result: typically the return value of
53+
the join point.
5454

5555
The following example shows a simple `MethodInterceptor` implementation:
5656

@@ -64,9 +64,9 @@ Java::
6464
6565
public Object invoke(MethodInvocation invocation) throws Throwable {
6666
System.out.println("Before: invocation=[" + invocation + "]");
67-
Object rval = invocation.proceed();
67+
Object result = invocation.proceed();
6868
System.out.println("Invocation returned");
69-
return rval;
69+
return result;
7070
}
7171
}
7272
----
@@ -79,9 +79,9 @@ Kotlin::
7979
8080
override fun invoke(invocation: MethodInvocation): Any {
8181
println("Before: invocation=[$invocation]")
82-
val rval = invocation.proceed()
82+
val result = invocation.proceed()
8383
println("Invocation returned")
84-
return rval
84+
return result
8585
}
8686
}
8787
----
@@ -105,7 +105,7 @@ currently define pointcut interfaces.
105105
[[aop-api-advice-before]]
106106
=== Before Advice
107107

108-
A simpler advice type is a before advice. This does not need a `MethodInvocation`
108+
A simpler advice type is a _before advice_. This does not need a `MethodInvocation`
109109
object, since it is called only before entering the method.
110110

111111
The main advantage of a before advice is that there is no need to invoke the `proceed()`
@@ -122,10 +122,6 @@ The following listing shows the `MethodBeforeAdvice` interface:
122122
}
123123
----
124124

125-
(Spring's API design would allow for
126-
field before advice, although the usual objects apply to field interception and it is
127-
unlikely for Spring to ever implement it.)
128-
129125
Note that the return type is `void`. Before advice can insert custom behavior before the join
130126
point runs but cannot change the return value. If a before advice throws an
131127
exception, it stops further execution of the interceptor chain. The exception
@@ -176,10 +172,10 @@ TIP: Before advice can be used with any pointcut.
176172
[[aop-api-advice-throws]]
177173
=== Throws Advice
178174

179-
Throws advice is invoked after the return of the join point if the join point threw
175+
_Throws advice_ is invoked after the return of the join point if the join point threw
180176
an exception. Spring offers typed throws advice. Note that this means that the
181177
`org.springframework.aop.ThrowsAdvice` interface does not contain any methods. It is a
182-
tag interface identifying that the given object implements one or more typed throws
178+
marker interface identifying that the given object implements one or more typed throws
183179
advice methods. These should be in the following form:
184180

185181
[source,java,indent=0,subs="verbatim,quotes"]
@@ -189,9 +185,10 @@ advice methods. These should be in the following form:
189185

190186
Only the last argument is required. The method signatures may have either one or four
191187
arguments, depending on whether the advice method is interested in the method and
192-
arguments. The next two listing show classes that are examples of throws advice.
188+
arguments. The next two listings show classes that are examples of throws advice.
193189

194-
The following advice is invoked if a `RemoteException` is thrown (including from subclasses):
190+
The following advice is invoked if a `RemoteException` is thrown (including subclasses of
191+
`RemoteException`):
195192

196193
[tabs]
197194
======
@@ -220,9 +217,9 @@ Kotlin::
220217
----
221218
======
222219

223-
Unlike the preceding
224-
advice, the next example declares four arguments, so that it has access to the invoked method, method
225-
arguments, and target object. The following advice is invoked if a `ServletException` is thrown:
220+
Unlike the preceding advice, the next example declares four arguments, so that it has
221+
access to the invoked method, method arguments, and target object. The following advice
222+
is invoked if a `ServletException` is thrown:
226223

227224
[tabs]
228225
======
@@ -304,7 +301,7 @@ TIP: Throws advice can be used with any pointcut.
304301
[[aop-api-advice-after-returning]]
305302
=== After Returning Advice
306303

307-
An after returning advice in Spring must implement the
304+
An _after returning advice_ in Spring must implement the
308305
`org.springframework.aop.AfterReturningAdvice` interface, which the following listing shows:
309306

310307
[source,java,indent=0,subs="verbatim,quotes"]
@@ -368,7 +365,7 @@ TIP: After returning advice can be used with any pointcut.
368365
[[aop-api-advice-introduction]]
369366
=== Introduction Advice
370367

371-
Spring treats introduction advice as a special kind of interception advice.
368+
Spring treats _introduction advice_ as a special kind of interception advice.
372369

373370
Introduction requires an `IntroductionAdvisor` and an `IntroductionInterceptor` that
374371
implement the following interface:

spring-aop/src/main/java/org/springframework/aop/ThrowsAdvice.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,11 +27,11 @@
2727
* <p>Some examples of valid methods would be:
2828
*
2929
* <pre class="code">public void afterThrowing(Exception ex)</pre>
30-
* <pre class="code">public void afterThrowing(RemoteException)</pre>
30+
* <pre class="code">public void afterThrowing(RemoteException ex)</pre>
3131
* <pre class="code">public void afterThrowing(Method method, Object[] args, Object target, Exception ex)</pre>
3232
* <pre class="code">public void afterThrowing(Method method, Object[] args, Object target, ServletException ex)</pre>
3333
*
34-
* The first three arguments are optional, and only useful if we want further
34+
* <p>The first three arguments are optional, and only useful if we want further
3535
* information about the joinpoint, as in AspectJ <b>after-throwing</b> advice.
3636
*
3737
* <p><b>Note:</b> If a throws-advice method throws an exception itself, it will

0 commit comments

Comments
 (0)