From 66670cfd56983668729f70291e4be5076e7d8de0 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 24 Mar 2017 11:08:57 +0100 Subject: [PATCH] Clarification: Spring AOP pointcuts may match non-public methods Issue: SPR-15354 (cherry picked from commit b90d3d0) --- src/asciidoc/core-aop.adoc | 23 +++++++++++++---------- src/asciidoc/core-beans.adoc | 26 ++++++++++++++++---------- src/asciidoc/core-expressions.adoc | 2 +- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/asciidoc/core-aop.adoc b/src/asciidoc/core-aop.adoc index 8c8022c1c61..1d6c4ad25db 100644 --- a/src/asciidoc/core-aop.adoc +++ b/src/asciidoc/core-aop.adoc @@ -405,16 +405,20 @@ proxy (bound to `target`). [NOTE] ==== -Due to the proxy-based nature of Spring's AOP framework, protected methods are by -definition __not__ intercepted, neither for JDK proxies (where this isn't applicable) -nor for CGLIB proxies (where this is technically possible but not recommendable for AOP -purposes). As a consequence, any given pointcut will be matched against __public methods -only__! +Due to the proxy-based nature of Spring's AOP framework, calls within the target object +are by definition __not__ intercepted. For JDK proxies, only public interface method +calls on the proxy can be intercepted. With CGLIB, public and protected method calls on +the proxy will be intercepted, and even package-visible methods if necessary. However, +common interactions through proxies should always be designed through public signatures. -If your interception needs include protected/private methods or even constructors, -consider the use of Spring-driven <> instead of -Spring's proxy-based AOP framework. This constitutes a different mode of AOP usage with -different characteristics, so be sure to make yourself familiar with weaving first +Note that pointcut definitions are generally matched against any intercepted method. +If a pointcut is strictly meant to be public-only, even in a CGLIB proxy scenario with +potential non-public interactions through proxies, it needs to be defined accordingly. + +If your interception needs include method calls or even constructors within the target +class, consider the use of Spring-driven <> instead +of Spring's proxy-based AOP framework. This constitutes a different mode of AOP usage +with different characteristics, so be sure to make yourself familiar with weaving first before making a decision. ==== @@ -1558,7 +1562,6 @@ advisor, and aspect elements (note these must be declared in that order). [WARNING] ==== - The `` style of configuration makes heavy use of Spring's <> mechanism. This can cause issues (such as advice not being woven) if you are already using explicit auto-proxying via the use of diff --git a/src/asciidoc/core-beans.adoc b/src/asciidoc/core-beans.adoc index 543d047001d..a4472c1c8ea 100644 --- a/src/asciidoc/core-beans.adoc +++ b/src/asciidoc/core-beans.adoc @@ -1361,7 +1361,7 @@ element. - + ---- @@ -1375,7 +1375,7 @@ following snippet: - + ---- @@ -5412,7 +5412,7 @@ comma/semicolon/space-separated list that includes the parent package of each cl [NOTE] ==== for concision, the above may have used the `value` attribute of the -annotation, i.e. `ComponentScan("org.example")` +annotation, i.e. `@ComponentScan("org.example")` ==== 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: private Provider movieFinder; + @Inject + public void setMovieFinder(Provider movieFinder) { + this.movieFinder = movieFinder; + } + public void listMovies() { this.movieFinder.get().findMovies(...); ... @@ -8314,7 +8319,7 @@ synchronously. This means the `publishEvent()` method blocks until all listeners finished processing the event. One advantage of this synchronous and single-threaded approach is that when a listener receives an event, it operates inside the transaction context of the publisher if a transaction context is available. If another strategy for -event publication becomes necessary, refer to the JavaDoc for Spring's +event publication becomes necessary, refer to the javadoc for Spring's `ApplicationEventMulticaster` interface. The following example shows the bean definitions used to register and configure each of @@ -8381,9 +8386,10 @@ follows: } ---- -As you can see above, the method signature actually _infer_ which even type it listens to. This -also works for nested generics as long as the actual event resolves the generics parameter you -would filter on. +As you can see above, the method signature once again declares the event type it listens to, +but this time with a flexible name and without implementing a specific listener interface. +The event type can also be narrowed through generics as long as the actual event type +resolves your generic parameter in its implementation hierarchy. If your method should listen to several events or if you want to define it with no 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 ---- @EventListener({ContextStartedEvent.class, ContextRefreshedEvent.class}) public void handleContextStart() { - + ... } ---- @@ -8643,7 +8649,7 @@ platform's JMX server - all through Spring's standard transaction management and and JMX support facilities. Application components can also interact with the application server's JCA WorkManager through Spring's `TaskExecutor` abstraction. -Check out the JavaDoc of the +Check out the javadoc of the {api-spring-framework}/jca/context/SpringContextResourceAdapter.html[`SpringContextResourceAdapter`] class for the configuration details involved in RAR deployment. @@ -8651,7 +8657,7 @@ __For a simple deployment of a Spring ApplicationContext as a Java EE RAR file:_ all application classes into a RAR file, which is a standard JAR file with a different file extension. Add all required library JARs into the root of the RAR archive. Add a "META-INF/ra.xml" deployment descriptor (as shown in ``SpringContextResourceAdapter``s -JavaDoc) and the corresponding Spring XML bean definition file(s) (typically +javadoc) and the corresponding Spring XML bean definition file(s) (typically "META-INF/applicationContext.xml"), and drop the resulting RAR file into your application server's deployment directory. diff --git a/src/asciidoc/core-expressions.adoc b/src/asciidoc/core-expressions.adoc index 1dcfcb9dd86..d1ab1fc56ca 100644 --- a/src/asciidoc/core-expressions.adoc +++ b/src/asciidoc/core-expressions.adoc @@ -249,7 +249,7 @@ variables and functions are described in the language reference sections <> and <>. The `StandardEvaluationContext` is also where you can register custom ``ConstructorResolver``s, ``MethodResolver``s, and ``PropertyAccessor``s to extend how SpEL -evaluates expressions. Please refer to the JavaDoc of these classes for more details. +evaluates expressions. Please refer to the javadoc of these classes for more details. [[expressions-type-conversion]]