Skip to content

Commit c32c9ec

Browse files
committed
Explicit notes on advice mode proxy vs aspectj
Issue: SPR-16092
1 parent 40f3fb2 commit c32c9ec

File tree

5 files changed

+408
-398
lines changed

5 files changed

+408
-398
lines changed

spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -148,15 +148,19 @@
148148
* can be useful if you do not need to customize everything. See {@link CachingConfigurer}
149149
* Javadoc for further details.
150150
*
151-
* <p>The {@link #mode()} attribute controls how advice is applied; if the mode is
152-
* {@link AdviceMode#PROXY} (the default), then the other attributes such as
153-
* {@link #proxyTargetClass()} control the behavior of the proxying.
151+
* <p>The {@link #mode} attribute controls how advice is applied: If the mode is
152+
* {@link AdviceMode#PROXY} (the default), then the other attributes control the behavior
153+
* of the proxying. Please note that proxy mode allows for interception of calls through
154+
* the proxy only; local calls within the same class cannot get intercepted that way.
154155
*
155-
* <p>If the {@linkplain #mode} is set to {@link AdviceMode#ASPECTJ}, then the
156-
* {@link #proxyTargetClass()} attribute is obsolete. Note also that in this case the
157-
* {@code spring-aspects} module JAR must be present on the classpath.
156+
* <p>Note that if the {@linkplain #mode} is set to {@link AdviceMode#ASPECTJ}, then the
157+
* value of the {@link #proxyTargetClass} attribute will be ignored. Note also that in
158+
* this case the {@code spring-aspects} module JAR must be present on the classpath, with
159+
* compile-time weaving or load-time weaving applying the aspect to the affected classes.
160+
* There is no proxy involved in such a scenario; local calls will be intercepted as well.
158161
*
159162
* @author Chris Beams
163+
* @author Juergen Hoeller
160164
* @since 3.1
161165
* @see CachingConfigurer
162166
* @see CachingConfigurationSelector
@@ -183,16 +187,21 @@
183187
boolean proxyTargetClass() default false;
184188

185189
/**
186-
* Indicate how caching advice should be applied. The default is
187-
* {@link AdviceMode#PROXY}.
188-
* @see AdviceMode
190+
* Indicate how caching advice should be applied.
191+
* <p><b>The default is {@link AdviceMode#PROXY}.</b>
192+
* Please note that proxy mode allows for interception of calls through the proxy
193+
* only. Local calls within the same class cannot get intercepted that way;
194+
* a caching annotation on such a method within a local call will be ignored
195+
* since Spring's interceptor does not even kick in for such a runtime scenario.
196+
* For a more advanced mode of interception, consider switching this to
197+
* {@link AdviceMode#ASPECTJ}.
189198
*/
190199
AdviceMode mode() default AdviceMode.PROXY;
191200

192201
/**
193202
* Indicate the ordering of the execution of the caching advisor
194203
* when multiple advices are applied at a specific joinpoint.
195-
* The default is {@link Ordered#LOWEST_PRECEDENCE}.
204+
* <p>The default is {@link Ordered#LOWEST_PRECEDENCE}.
196205
*/
197206
int order() default Ordered.LOWEST_PRECEDENCE;
198207

spring-context/src/main/java/org/springframework/scheduling/annotation/EnableAsync.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -58,14 +58,6 @@
5858
* }
5959
* }</pre>
6060
*
61-
* <p>The {@link #mode} attribute controls how advice is applied; if the mode is
62-
* {@link AdviceMode#PROXY} (the default), then the other attributes control the behavior
63-
* of the proxying.
64-
*
65-
* <p>Note that if the {@linkplain #mode} is set to {@link AdviceMode#ASPECTJ}, then the
66-
* value of the {@link #proxyTargetClass} attribute will be ignored. Note also that in
67-
* this case the {@code spring-aspects} module JAR must be present on the classpath.
68-
*
6961
* <p>By default, Spring will be searching for an associated thread pool definition:
7062
* either a unique {@link org.springframework.core.task.TaskExecutor} bean in the context,
7163
* or an {@link java.util.concurrent.Executor} bean named "taskExecutor" otherwise. If
@@ -140,6 +132,17 @@
140132
* demonstrates how the JavaConfig-based approach allows for maximum configurability
141133
* through direct access to actual componentry.
142134
*
135+
* <p>The {@link #mode} attribute controls how advice is applied: If the mode is
136+
* {@link AdviceMode#PROXY} (the default), then the other attributes control the behavior
137+
* of the proxying. Please note that proxy mode allows for interception of calls through
138+
* the proxy only; local calls within the same class cannot get intercepted that way.
139+
*
140+
* <p>Note that if the {@linkplain #mode} is set to {@link AdviceMode#ASPECTJ}, then the
141+
* value of the {@link #proxyTargetClass} attribute will be ignored. Note also that in
142+
* this case the {@code spring-aspects} module JAR must be present on the classpath, with
143+
* compile-time weaving or load-time weaving applying the aspect to the affected classes.
144+
* There is no proxy involved in such a scenario; local calls will be intercepted as well.
145+
*
143146
* @author Chris Beams
144147
* @author Juergen Hoeller
145148
* @author Stephane Nicoll
@@ -182,8 +185,13 @@
182185

183186
/**
184187
* Indicate how async advice should be applied.
185-
* <p>The default is {@link AdviceMode#PROXY}.
186-
* @see AdviceMode
188+
* <p><b>The default is {@link AdviceMode#PROXY}.</b>
189+
* Please note that proxy mode allows for interception of calls through the proxy
190+
* only. Local calls within the same class cannot get intercepted that way; an
191+
* {@link Async} annotation on such a method within a local call will be ignored
192+
* since Spring's interceptor does not even kick in for such a runtime scenario.
193+
* For a more advanced mode of interception, consider switching this to
194+
* {@link AdviceMode#ASPECTJ}.
187195
*/
188196
AdviceMode mode() default AdviceMode.PROXY;
189197

spring-tx/src/main/java/org/springframework/transaction/annotation/EnableTransactionManagement.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -131,15 +131,19 @@
131131
* {@code @Transactional} methods. See {@link TransactionManagementConfigurer} Javadoc
132132
* for further details.
133133
*
134-
* <p>The {@link #mode()} attribute controls how advice is applied; if the mode is
134+
* <p>The {@link #mode} attribute controls how advice is applied: If the mode is
135135
* {@link AdviceMode#PROXY} (the default), then the other attributes control the behavior
136-
* of the proxying.
136+
* of the proxying. Please note that proxy mode allows for interception of calls through
137+
* the proxy only; local calls within the same class cannot get intercepted that way.
137138
*
138-
* <p>If the {@linkplain #mode} is set to {@link AdviceMode#ASPECTJ}, then the
139-
* {@link #proxyTargetClass()} attribute is obsolete. Note also that in this case the
140-
* {@code spring-aspects} module JAR must be present on the classpath.
139+
* <p>Note that if the {@linkplain #mode} is set to {@link AdviceMode#ASPECTJ}, then the
140+
* value of the {@link #proxyTargetClass} attribute will be ignored. Note also that in
141+
* this case the {@code spring-aspects} module JAR must be present on the classpath, with
142+
* compile-time weaving or load-time weaving applying the aspect to the affected classes.
143+
* There is no proxy involved in such a scenario; local calls will be intercepted as well.
141144
*
142145
* @author Chris Beams
146+
* @author Juergen Hoeller
143147
* @since 3.1
144148
* @see TransactionManagementConfigurer
145149
* @see TransactionManagementConfigurationSelector
@@ -167,16 +171,21 @@
167171
boolean proxyTargetClass() default false;
168172

169173
/**
170-
* Indicate how transactional advice should be applied. The default is
171-
* {@link AdviceMode#PROXY}.
172-
* @see AdviceMode
174+
* Indicate how transactional advice should be applied.
175+
* <p><b>The default is {@link AdviceMode#PROXY}.</b>
176+
* Please note that proxy mode allows for interception of calls through the proxy
177+
* only. Local calls within the same class cannot get intercepted that way; an
178+
* {@link Transactional} annotation on such a method within a local call will be
179+
* ignored since Spring's interceptor does not even kick in for such a runtime
180+
* scenario. For a more advanced mode of interception, consider switching this to
181+
* {@link AdviceMode#ASPECTJ}.
173182
*/
174183
AdviceMode mode() default AdviceMode.PROXY;
175184

176185
/**
177186
* Indicate the ordering of the execution of the transaction advisor
178187
* when multiple advices are applied at a specific joinpoint.
179-
* The default is {@link Ordered#LOWEST_PRECEDENCE}.
188+
* <p>The default is {@link Ordered#LOWEST_PRECEDENCE}.
180189
*/
181190
int order() default Ordered.LOWEST_PRECEDENCE;
182191

0 commit comments

Comments
 (0)