@@ -193,9 +193,8 @@ in the advice associated with a method invocation getting a chance to run.
193
193
Okay, so what is to be done about this? The best approach (the term "best" is used
194
194
loosely here) is to refactor your code such that the self-invocation does not happen.
195
195
This does entail some work on your part, but it is the best, least-invasive approach.
196
- The next approach is absolutely horrendous, and we hesitate to point it out, precisely
197
- because it is so horrendous. You can (painful as it is to us) totally tie the logic
198
- within your class to Spring AOP, as the following example shows:
196
+ The next approach is a little counter-intuitive, you can inject self by field or method
197
+ (constructor injection is not supported), as the following example shows:
199
198
200
199
[tabs]
201
200
======
@@ -205,9 +204,12 @@ Java::
205
204
----
206
205
public class SimplePojo implements Pojo {
207
206
207
+ @Autowired
208
+ private SimplePojo self;
209
+
208
210
public void foo() {
209
- // this works, but... gah!
210
- ((Pojo) AopContext.currentProxy()) .bar();
211
+ // this works
212
+ self .bar();
211
213
}
212
214
213
215
public void bar() {
@@ -222,9 +224,12 @@ Kotlin::
222
224
----
223
225
class SimplePojo : Pojo {
224
226
227
+ @Autowired
228
+ private lateinit var self: SimplePojo
229
+
225
230
fun foo() {
226
- // this works, but... gah!
227
- (AopContext.currentProxy() as Pojo) .bar()
231
+ // this works
232
+ self .bar()
228
233
}
229
234
230
235
fun bar() {
0 commit comments