1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
28
28
import org .springframework .aop .TargetSource ;
29
29
import org .springframework .aop .framework .ProxyFactory ;
30
30
import org .springframework .aop .support .AopUtils ;
31
+ import org .springframework .aop .support .DefaultIntroductionAdvisor ;
31
32
import org .springframework .aop .target .SingletonTargetSource ;
32
33
import org .springframework .beans .MutablePropertyValues ;
33
34
import org .springframework .beans .factory .BeanFactory ;
@@ -219,7 +220,7 @@ public void testAutoProxyCreatorWithFallbackToDynamicProxy() {
219
220
220
221
MutablePropertyValues pvs = new MutablePropertyValues ();
221
222
pvs .add ("proxyFactoryBean" , "false" );
222
- sac .registerSingleton ("testAutoProxyCreator" , TestAutoProxyCreator .class , pvs );
223
+ sac .registerSingleton ("testAutoProxyCreator" , IntroductionTestAutoProxyCreator .class , pvs );
223
224
224
225
sac .registerSingleton ("noInterfaces" , NoInterfaces .class );
225
226
sac .registerSingleton ("containerCallbackInterfacesOnly" , ContainerCallbackInterfacesOnly .class );
@@ -248,9 +249,9 @@ public void testAutoProxyCreatorWithFallbackToDynamicProxy() {
248
249
singletonNoInterceptor .getName ();
249
250
assertThat (tapc .testInterceptor .nrOfInvocations ).isEqualTo (0 );
250
251
singletonToBeProxied .getAge ();
251
- assertThat (tapc .testInterceptor .nrOfInvocations ).isEqualTo (1 );
252
- prototypeToBeProxied .getSpouse ();
253
252
assertThat (tapc .testInterceptor .nrOfInvocations ).isEqualTo (2 );
253
+ prototypeToBeProxied .getSpouse ();
254
+ assertThat (tapc .testInterceptor .nrOfInvocations ).isEqualTo (4 );
254
255
}
255
256
256
257
@ Test
@@ -404,7 +405,7 @@ protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String name,
404
405
else if (name .endsWith ("ToBeProxied" )) {
405
406
boolean isFactoryBean = FactoryBean .class .isAssignableFrom (beanClass );
406
407
if ((this .proxyFactoryBean && isFactoryBean ) || (this .proxyObject && !isFactoryBean )) {
407
- return new Object [] { this . testInterceptor } ;
408
+ return getAdvicesAndAdvisors () ;
408
409
}
409
410
else {
410
411
return DO_NOT_PROXY ;
@@ -414,6 +415,10 @@ else if (name.endsWith("ToBeProxied")) {
414
415
return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS ;
415
416
}
416
417
}
418
+
419
+ protected Object [] getAdvicesAndAdvisors () {
420
+ return new Object [] {this .testInterceptor };
421
+ }
417
422
}
418
423
419
424
@@ -426,6 +431,17 @@ public FallbackTestAutoProxyCreator() {
426
431
}
427
432
428
433
434
+ @ SuppressWarnings ("serial" )
435
+ public static class IntroductionTestAutoProxyCreator extends TestAutoProxyCreator {
436
+
437
+ protected Object [] getAdvicesAndAdvisors () {
438
+ DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor (this .testInterceptor );
439
+ advisor .addInterface (Serializable .class );
440
+ return new Object [] {this .testInterceptor , advisor };
441
+ }
442
+ }
443
+
444
+
429
445
/**
430
446
* Interceptor that counts the number of non-finalize method calls.
431
447
*/
0 commit comments