42
42
import org .springframework .beans .PropertyValues ;
43
43
import org .springframework .beans .factory .BeanFactory ;
44
44
import org .springframework .beans .factory .BeanFactoryAware ;
45
+ import org .springframework .beans .factory .FactoryBean ;
45
46
import org .springframework .beans .factory .config .ConfigurableBeanFactory ;
46
47
import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
47
48
import org .springframework .beans .factory .config .SmartInstantiationAwareBeanPostProcessor ;
49
+ import org .springframework .util .StringUtils ;
48
50
49
51
/**
50
52
* {@link org.springframework.beans.factory.config.BeanPostProcessor} implementation
@@ -125,8 +127,6 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
125
127
126
128
private BeanFactory beanFactory ;
127
129
128
- private final Map <Object , Boolean > advisedBeans = new ConcurrentHashMap <Object , Boolean >(64 );
129
-
130
130
private final Set <String > targetSourcedBeans =
131
131
Collections .newSetFromMap (new ConcurrentHashMap <String , Boolean >(16 ));
132
132
@@ -135,6 +135,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
135
135
136
136
private final Map <Object , Class <?>> proxyTypes = new ConcurrentHashMap <Object , Class <?>>(16 );
137
137
138
+ private final Map <Object , Boolean > advisedBeans = new ConcurrentHashMap <Object , Boolean >(256 );
139
+
138
140
139
141
/**
140
142
* Set whether or not the proxy should be frozen, preventing advice
@@ -214,6 +216,9 @@ protected BeanFactory getBeanFactory() {
214
216
215
217
@ Override
216
218
public Class <?> predictBeanType (Class <?> beanClass , String beanName ) {
219
+ if (this .proxyTypes .isEmpty ()) {
220
+ return null ;
221
+ }
217
222
Object cacheKey = getCacheKey (beanClass , beanName );
218
223
return this .proxyTypes .get (cacheKey );
219
224
}
@@ -299,12 +304,23 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw
299
304
300
305
/**
301
306
* Build a cache key for the given bean class and bean name.
307
+ * <p>Note: As of 4.2.3, this implementation does not return a concatenated
308
+ * class/name String anymore but rather the most efficient cache key possible:
309
+ * a plain bean name, prepended with {@link BeanFactory#FACTORY_BEAN_PREFIX}
310
+ * in case of a {@code FactoryBean}; or if no bean name specified, then the
311
+ * given bean {@code Class} as-is.
302
312
* @param beanClass the bean class
303
313
* @param beanName the bean name
304
314
* @return the cache key for the given class and name
305
315
*/
306
316
protected Object getCacheKey (Class <?> beanClass , String beanName ) {
307
- return beanClass .getName () + "_" + beanName ;
317
+ if (StringUtils .hasLength (beanName )) {
318
+ return (FactoryBean .class .isAssignableFrom (beanClass ) ?
319
+ BeanFactory .FACTORY_BEAN_PREFIX + beanName : beanName );
320
+ }
321
+ else {
322
+ return beanClass ;
323
+ }
308
324
}
309
325
310
326
/**
@@ -420,7 +436,7 @@ protected TargetSource getCustomTargetSource(Class<?> beanClass, String beanName
420
436
protected Object createProxy (
421
437
Class <?> beanClass , String beanName , Object [] specificInterceptors , TargetSource targetSource ) {
422
438
423
- if (beanName != null && this .beanFactory instanceof ConfigurableListableBeanFactory ) {
439
+ if (this .beanFactory instanceof ConfigurableListableBeanFactory ) {
424
440
AutoProxyUtils .exposeTargetClass ((ConfigurableListableBeanFactory ) this .beanFactory , beanName , beanClass );
425
441
}
426
442
0 commit comments