Skip to content

Commit 66670cf

Browse files
committed
Clarification: Spring AOP pointcuts may match non-public methods
Issue: SPR-15354 (cherry picked from commit b90d3d0)
1 parent c31bfe6 commit 66670cf

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
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

+16-10
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ element.
13611361
13621362
<bean id="theClientBean" class="...">
13631363
<property name="targetName">
1364-
<idref bean="theTargetBean" />
1364+
<idref bean="theTargetBean"/>
13651365
</property>
13661366
</bean>
13671367
----
@@ -1375,7 +1375,7 @@ following snippet:
13751375
<bean id="theTargetBean" class="..." />
13761376
13771377
<bean id="client" class="...">
1378-
<property name="targetName" value="theTargetBean" />
1378+
<property name="targetName" value="theTargetBean"/>
13791379
</bean>
13801380
----
13811381

@@ -5412,7 +5412,7 @@ comma/semicolon/space-separated list that includes the parent package of each cl
54125412
[NOTE]
54135413
====
54145414
for concision, the above may have used the `value` attribute of the
5415-
annotation, i.e. `ComponentScan("org.example")`
5415+
annotation, i.e. `@ComponentScan("org.example")`
54165416
====
54175417

54185418
The following is an alternative using XML
@@ -5965,6 +5965,11 @@ other beans through a `Provider.get()` call. As a variant of the example above:
59655965
59665966
private Provider<MovieFinder> movieFinder;
59675967
5968+
@Inject
5969+
public void setMovieFinder(Provider<MovieFinder> movieFinder) {
5970+
this.movieFinder = movieFinder;
5971+
}
5972+
59685973
public void listMovies() {
59695974
this.movieFinder.get().findMovies(...);
59705975
...
@@ -8314,7 +8319,7 @@ synchronously. This means the `publishEvent()` method blocks until all listeners
83148319
finished processing the event. One advantage of this synchronous and single-threaded
83158320
approach is that when a listener receives an event, it operates inside the transaction
83168321
context of the publisher if a transaction context is available. If another strategy for
8317-
event publication becomes necessary, refer to the JavaDoc for Spring's
8322+
event publication becomes necessary, refer to the javadoc for Spring's
83188323
`ApplicationEventMulticaster` interface.
83198324

83208325
The following example shows the bean definitions used to register and configure each of
@@ -8381,9 +8386,10 @@ follows:
83818386
}
83828387
----
83838388

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

83888394
If your method should listen to several events or if you want to define it with no
83898395
parameter at all, the event type(s) can also be specified on the annotation itself:
@@ -8393,7 +8399,7 @@ parameter at all, the event type(s) can also be specified on the annotation itse
83938399
----
83948400
@EventListener({ContextStartedEvent.class, ContextRefreshedEvent.class})
83958401
public void handleContextStart() {
8396-
8402+
...
83978403
}
83988404
----
83998405

@@ -8643,15 +8649,15 @@ platform's JMX server - all through Spring's standard transaction management and
86438649
and JMX support facilities. Application components can also interact with the
86448650
application server's JCA WorkManager through Spring's `TaskExecutor` abstraction.
86458651

8646-
Check out the JavaDoc of the
8652+
Check out the javadoc of the
86478653
{api-spring-framework}/jca/context/SpringContextResourceAdapter.html[`SpringContextResourceAdapter`]
86488654
class for the configuration details involved in RAR deployment.
86498655

86508656
__For a simple deployment of a Spring ApplicationContext as a Java EE RAR file:__ package
86518657
all application classes into a RAR file, which is a standard JAR file with a different
86528658
file extension. Add all required library JARs into the root of the RAR archive. Add a
86538659
"META-INF/ra.xml" deployment descriptor (as shown in ``SpringContextResourceAdapter``s
8654-
JavaDoc) and the corresponding Spring XML bean definition file(s) (typically
8660+
javadoc) and the corresponding Spring XML bean definition file(s) (typically
86558661
"META-INF/applicationContext.xml"), and drop the resulting RAR file into your
86568662
application server's deployment directory.
86578663

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)