@@ -285,13 +285,15 @@ public <T> T createBean(Class<T> beanClass) throws BeansException {
285
285
// Use prototype bean definition, to avoid registering bean as dependent bean.
286
286
RootBeanDefinition bd = new RootBeanDefinition (beanClass );
287
287
bd .setScope (SCOPE_PROTOTYPE );
288
+ bd .allowCaching = false ;
288
289
return (T ) createBean (beanClass .getName (), bd , null );
289
290
}
290
291
291
292
public void autowireBean (Object existingBean ) {
292
293
// Use non-singleton bean definition, to avoid registering bean as dependent bean.
293
294
RootBeanDefinition bd = new RootBeanDefinition (ClassUtils .getUserClass (existingBean ));
294
295
bd .setScope (BeanDefinition .SCOPE_PROTOTYPE );
296
+ bd .allowCaching = false ;
295
297
BeanWrapper bw = new BeanWrapperImpl (existingBean );
296
298
initBeanWrapper (bw );
297
299
populateBean (bd .getBeanClass ().getName (), bd , bw );
@@ -310,6 +312,7 @@ public Object configureBean(Object existingBean, String beanName) throws BeansEx
310
312
if (bd == null ) {
311
313
bd = new RootBeanDefinition (mbd );
312
314
bd .setScope (BeanDefinition .SCOPE_PROTOTYPE );
315
+ bd .allowCaching = false ;
313
316
}
314
317
BeanWrapper bw = new BeanWrapperImpl (existingBean );
315
318
initBeanWrapper (bw );
@@ -1053,7 +1056,7 @@ protected BeanWrapper autowireConstructor(
1053
1056
* @param mbd the bean definition for the bean
1054
1057
* @param bw BeanWrapper with bean instance
1055
1058
*/
1056
- protected void populateBean (String beanName , AbstractBeanDefinition mbd , BeanWrapper bw ) {
1059
+ protected void populateBean (String beanName , RootBeanDefinition mbd , BeanWrapper bw ) {
1057
1060
PropertyValues pvs = mbd .getPropertyValues ();
1058
1061
1059
1062
if (bw == null ) {
@@ -1109,7 +1112,7 @@ protected void populateBean(String beanName, AbstractBeanDefinition mbd, BeanWra
1109
1112
boolean needsDepCheck = (mbd .getDependencyCheck () != RootBeanDefinition .DEPENDENCY_CHECK_NONE );
1110
1113
1111
1114
if (hasInstAwareBpps || needsDepCheck ) {
1112
- PropertyDescriptor [] filteredPds = filterPropertyDescriptorsForDependencyCheck (bw );
1115
+ PropertyDescriptor [] filteredPds = filterPropertyDescriptorsForDependencyCheck (bw , mbd . allowCaching );
1113
1116
if (hasInstAwareBpps ) {
1114
1117
for (BeanPostProcessor bp : getBeanPostProcessors ()) {
1115
1118
if (bp instanceof InstantiationAwareBeanPostProcessor ) {
@@ -1237,34 +1240,51 @@ protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, Be
1237
1240
1238
1241
/**
1239
1242
* Extract a filtered set of PropertyDescriptors from the given BeanWrapper,
1240
- * excluding ignored dependency types or properties defined on ignored
1241
- * dependency interfaces.
1243
+ * excluding ignored dependency types or properties defined on ignored dependency interfaces.
1242
1244
* @param bw the BeanWrapper the bean was created with
1245
+ * @param cache whether to cache filtered PropertyDescriptors for the given bean Class
1243
1246
* @return the filtered PropertyDescriptors
1244
1247
* @see #isExcludedFromDependencyCheck
1248
+ * @see #filterPropertyDescriptorsForDependencyCheck(org.springframework.beans.BeanWrapper)
1245
1249
*/
1246
- protected PropertyDescriptor [] filterPropertyDescriptorsForDependencyCheck (BeanWrapper bw ) {
1250
+ protected PropertyDescriptor [] filterPropertyDescriptorsForDependencyCheck (BeanWrapper bw , boolean cache ) {
1247
1251
PropertyDescriptor [] filtered = this .filteredPropertyDescriptorsCache .get (bw .getWrappedClass ());
1248
1252
if (filtered == null ) {
1249
- synchronized (this .filteredPropertyDescriptorsCache ) {
1250
- filtered = this .filteredPropertyDescriptorsCache .get (bw .getWrappedClass ());
1251
- if (filtered == null ) {
1252
- List <PropertyDescriptor > pds =
1253
- new LinkedList <PropertyDescriptor >(Arrays .asList (bw .getPropertyDescriptors ()));
1254
- for (Iterator <PropertyDescriptor > it = pds .iterator (); it .hasNext ();) {
1255
- PropertyDescriptor pd = it .next ();
1256
- if (isExcludedFromDependencyCheck (pd )) {
1257
- it .remove ();
1258
- }
1253
+ if (cache ) {
1254
+ synchronized (this .filteredPropertyDescriptorsCache ) {
1255
+ filtered = this .filteredPropertyDescriptorsCache .get (bw .getWrappedClass ());
1256
+ if (filtered == null ) {
1257
+ filtered = filterPropertyDescriptorsForDependencyCheck (bw );
1258
+ this .filteredPropertyDescriptorsCache .put (bw .getWrappedClass (), filtered );
1259
1259
}
1260
- filtered = pds .toArray (new PropertyDescriptor [pds .size ()]);
1261
- this .filteredPropertyDescriptorsCache .put (bw .getWrappedClass (), filtered );
1262
1260
}
1263
1261
}
1262
+ else {
1263
+ filtered = filterPropertyDescriptorsForDependencyCheck (bw );
1264
+ }
1264
1265
}
1265
1266
return filtered ;
1266
1267
}
1267
1268
1269
+ /**
1270
+ * Extract a filtered set of PropertyDescriptors from the given BeanWrapper,
1271
+ * excluding ignored dependency types or properties defined on ignored dependency interfaces.
1272
+ * @param bw the BeanWrapper the bean was created with
1273
+ * @return the filtered PropertyDescriptors
1274
+ * @see #isExcludedFromDependencyCheck
1275
+ */
1276
+ protected PropertyDescriptor [] filterPropertyDescriptorsForDependencyCheck (BeanWrapper bw ) {
1277
+ List <PropertyDescriptor > pds =
1278
+ new LinkedList <PropertyDescriptor >(Arrays .asList (bw .getPropertyDescriptors ()));
1279
+ for (Iterator <PropertyDescriptor > it = pds .iterator (); it .hasNext ();) {
1280
+ PropertyDescriptor pd = it .next ();
1281
+ if (isExcludedFromDependencyCheck (pd )) {
1282
+ it .remove ();
1283
+ }
1284
+ }
1285
+ return pds .toArray (new PropertyDescriptor [pds .size ()]);
1286
+ }
1287
+
1268
1288
/**
1269
1289
* Determine whether the given bean property is excluded from dependency checks.
1270
1290
* <p>This implementation excludes properties defined by CGLIB and
0 commit comments