Skip to content

Commit b90d3d0

Browse files
committed
Clarification: Spring AOP pointcuts may match non-public methods
Issue: SPR-15354
1 parent b2a6a57 commit b90d3d0

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

src/asciidoc/core-aop.adoc

+14-11
Original file line numberDiff line numberDiff line change
@@ -405,16 +405,20 @@ proxy (bound to `target`).
405405

406406
[NOTE]
407407
====
408-
Due to the proxy-based nature of Spring's AOP framework, protected methods are by
409-
definition __not__ intercepted, neither for JDK proxies (where this isn't applicable)
410-
nor for CGLIB proxies (where this is technically possible but not recommendable for AOP
411-
purposes). As a consequence, any given pointcut will be matched against __public methods
412-
only__!
413-
414-
If your interception needs include protected/private methods or even constructors,
415-
consider the use of Spring-driven <<aop-aj-ltw,native AspectJ weaving>> instead of
416-
Spring's proxy-based AOP framework. This constitutes a different mode of AOP usage with
417-
different characteristics, so be sure to make yourself familiar with weaving first
408+
Due to the proxy-based nature of Spring's AOP framework, calls within the target object
409+
are by definition __not__ intercepted. For JDK proxies, only public interface method
410+
calls on the proxy can be intercepted. With CGLIB, public and protected method calls on
411+
the proxy will be intercepted, and even package-visible methods if necessary. However,
412+
common interactions through proxies should always be designed through public signatures.
413+
414+
Note that pointcut definitions are generally matched against any intercepted method.
415+
If a pointcut is strictly meant to be public-only, even in a CGLIB proxy scenario with
416+
potential non-public interactions through proxies, it needs to be defined accordingly.
417+
418+
If your interception needs include method calls or even constructors within the target
419+
class, consider the use of Spring-driven <<aop-aj-ltw,native AspectJ weaving>> instead
420+
of Spring's proxy-based AOP framework. This constitutes a different mode of AOP usage
421+
with different characteristics, so be sure to make yourself familiar with weaving first
418422
before making a decision.
419423
====
420424

@@ -1558,7 +1562,6 @@ advisor, and aspect elements (note these must be declared in that order).
15581562

15591563
[WARNING]
15601564
====
1561-
15621565
The `<aop:config>` style of configuration makes heavy use of Spring's
15631566
<<aop-autoproxy,auto-proxying>> mechanism. This can cause issues (such as advice not
15641567
being woven) if you are already using explicit auto-proxying via the use of

src/asciidoc/core-beans.adoc

+8-7
Original file line numberDiff line numberDiff line change
@@ -8329,7 +8329,7 @@ synchronously. This means the `publishEvent()` method blocks until all listeners
83298329
finished processing the event. One advantage of this synchronous and single-threaded
83308330
approach is that when a listener receives an event, it operates inside the transaction
83318331
context of the publisher if a transaction context is available. If another strategy for
8332-
event publication becomes necessary, refer to the JavaDoc for Spring's
8332+
event publication becomes necessary, refer to the javadoc for Spring's
83338333
`ApplicationEventMulticaster` interface.
83348334

83358335
The following example shows the bean definitions used to register and configure each of
@@ -8396,9 +8396,10 @@ follows:
83968396
}
83978397
----
83988398

8399-
As you can see above, the method signature actually _infer_ which even type it listens to. This
8400-
also works for nested generics as long as the actual event resolves the generics parameter you
8401-
would filter on.
8399+
As you can see above, the method signature once again declares the event type it listens to,
8400+
but this time with a flexible name and without implementing a specific listener interface.
8401+
The event type can also be narrowed through generics as long as the actual event type
8402+
resolves your generic parameter in its implementation hierarchy.
84028403

84038404
If your method should listen to several events or if you want to define it with no
84048405
parameter at all, the event type(s) can also be specified on the annotation itself:
@@ -8408,7 +8409,7 @@ parameter at all, the event type(s) can also be specified on the annotation itse
84088409
----
84098410
@EventListener({ContextStartedEvent.class, ContextRefreshedEvent.class})
84108411
public void handleContextStart() {
8411-
8412+
...
84128413
}
84138414
----
84148415

@@ -8658,15 +8659,15 @@ platform's JMX server - all through Spring's standard transaction management and
86588659
and JMX support facilities. Application components can also interact with the
86598660
application server's JCA WorkManager through Spring's `TaskExecutor` abstraction.
86608661

8661-
Check out the JavaDoc of the
8662+
Check out the javadoc of the
86628663
{api-spring-framework}/jca/context/SpringContextResourceAdapter.html[`SpringContextResourceAdapter`]
86638664
class for the configuration details involved in RAR deployment.
86648665

86658666
__For a simple deployment of a Spring ApplicationContext as a Java EE RAR file:__ package
86668667
all application classes into a RAR file, which is a standard JAR file with a different
86678668
file extension. Add all required library JARs into the root of the RAR archive. Add a
86688669
"META-INF/ra.xml" deployment descriptor (as shown in ``SpringContextResourceAdapter``s
8669-
JavaDoc) and the corresponding Spring XML bean definition file(s) (typically
8670+
javadoc) and the corresponding Spring XML bean definition file(s) (typically
86708671
"META-INF/applicationContext.xml"), and drop the resulting RAR file into your
86718672
application server's deployment directory.
86728673

src/asciidoc/core-expressions.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ variables and functions are described in the language reference sections
249249
<<expressions-ref-variables,Variables>> and <<expressions-ref-functions,Functions>>. The
250250
`StandardEvaluationContext` is also where you can register custom
251251
``ConstructorResolver``s, ``MethodResolver``s, and ``PropertyAccessor``s to extend how SpEL
252-
evaluates expressions. Please refer to the JavaDoc of these classes for more details.
252+
evaluates expressions. Please refer to the javadoc of these classes for more details.
253253

254254

255255
[[expressions-type-conversion]]

0 commit comments

Comments
 (0)