@@ -165,6 +165,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
165165 /** List of bean definition names, in registration order */
166166 private final List <String > beanDefinitionNames = new ArrayList <String >();
167167
168+ /** Unmodifiable view of beanDefinitionNames */
169+ private final List <String > unmodifiableBeanDefinitionNames = Collections .unmodifiableList (this .beanDefinitionNames );
170+
168171 /** Whether bean definition metadata may be cached for all beans */
169172 private boolean configurationFrozen = false ;
170173
@@ -227,6 +230,15 @@ public void setAllowEagerClassLoading(boolean allowEagerClassLoading) {
227230 this .allowEagerClassLoading = allowEagerClassLoading ;
228231 }
229232
233+ /**
234+ * Return if the factory is allowed to eagerly load bean classes.
235+ * @see #setAllowEagerClassLoading(boolean)
236+ * @since 4.1.2
237+ */
238+ public boolean isAllowEagerClassLoading () {
239+ return this .allowEagerClassLoading ;
240+ }
241+
230242 /**
231243 * Set a {@link java.util.Comparator} for dependency Lists and arrays.
232244 * @see org.springframework.core.OrderComparator
@@ -288,6 +300,10 @@ public void copyConfigurationFrom(ConfigurableBeanFactory otherFactory) {
288300 }
289301 }
290302
303+ @ Override
304+ public Class <?> predictBeanType (String beanName , RootBeanDefinition mbd , Class <?>... typesToMatch ) {
305+ return super .predictBeanType (beanName , mbd , typesToMatch );
306+ }
291307
292308 //---------------------------------------------------------------------
293309 // Implementation of ListableBeanFactory interface
@@ -362,6 +378,14 @@ public String[] getBeanDefinitionNames() {
362378 }
363379 }
364380
381+ /**
382+ * Return an unmodifiable collection containing the bean definition names.
383+ * @since 4.1.2
384+ */
385+ public Collection <String > getBeanDefinitionNamesCollection () {
386+ return this .unmodifiableBeanDefinitionNames ;
387+ }
388+
365389 @ Override
366390 public String [] getBeanNamesForType (Class <?> type ) {
367391 return getBeanNamesForType (type , true , true );
@@ -389,8 +413,7 @@ private String[] doGetBeanNamesForType(Class<?> type, boolean includeNonSingleto
389413 List <String > result = new ArrayList <String >();
390414
391415 // Check all bean definitions.
392- String [] beanDefinitionNames = getBeanDefinitionNames ();
393- for (String beanName : beanDefinitionNames ) {
416+ for (String beanName : getBeanDefinitionNamesCollection ()) {
394417 // Only consider bean as eligible if the bean name
395418 // is not defined as alias for some other bean.
396419 if (!isAlias (beanName )) {
@@ -438,8 +461,7 @@ private String[] doGetBeanNamesForType(Class<?> type, boolean includeNonSingleto
438461 }
439462
440463 // Check singletons too, to catch manually registered singletons.
441- String [] singletonNames = getSingletonNames ();
442- for (String beanName : singletonNames ) {
464+ for (String beanName : getSingletonNamesCollection ()) {
443465 // Only check if manually registered.
444466 if (!containsBeanDefinition (beanName )) {
445467 // In case of FactoryBean, match object created by FactoryBean.
@@ -512,13 +534,13 @@ public <T> Map<String, T> getBeansOfType(Class<T> type, boolean includeNonSingle
512534 @ Override
513535 public String [] getBeanNamesForAnnotation (Class <? extends Annotation > annotationType ) {
514536 List <String > results = new ArrayList <String >();
515- for (String beanName : getBeanDefinitionNames ()) {
537+ for (String beanName : getBeanDefinitionNamesCollection ()) {
516538 BeanDefinition beanDefinition = getBeanDefinition (beanName );
517539 if (!beanDefinition .isAbstract () && findAnnotationOnBean (beanName , annotationType ) != null ) {
518540 results .add (beanName );
519541 }
520542 }
521- for (String beanName : getSingletonNames ()) {
543+ for (String beanName : getSingletonNamesCollection ()) {
522544 if (!results .contains (beanName ) && findAnnotationOnBean (beanName , annotationType ) != null ) {
523545 results .add (beanName );
524546 }
@@ -529,13 +551,13 @@ public String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotation
529551 @ Override
530552 public Map <String , Object > getBeansWithAnnotation (Class <? extends Annotation > annotationType ) {
531553 Map <String , Object > results = new LinkedHashMap <String , Object >();
532- for (String beanName : getBeanDefinitionNames ()) {
554+ for (String beanName : getBeanDefinitionNamesCollection ()) {
533555 BeanDefinition beanDefinition = getBeanDefinition (beanName );
534556 if (!beanDefinition .isAbstract () && findAnnotationOnBean (beanName , annotationType ) != null ) {
535557 results .put (beanName , getBean (beanName ));
536558 }
537559 }
538- for (String beanName : getSingletonNames ()) {
560+ for (String beanName : getSingletonNamesCollection ()) {
539561 if (!results .containsKey (beanName ) && findAnnotationOnBean (beanName , annotationType ) != null ) {
540562 results .put (beanName , getBean (beanName ));
541563 }
@@ -1266,7 +1288,7 @@ private void raiseNoSuchBeanDefinitionException(
12661288 public String toString () {
12671289 StringBuilder sb = new StringBuilder (ObjectUtils .identityToString (this ));
12681290 sb .append (": defining beans [" );
1269- sb .append (StringUtils .arrayToCommaDelimitedString ( getBeanDefinitionNames ()));
1291+ sb .append (StringUtils .collectionToCommaDelimitedString ( getBeanDefinitionNamesCollection ()));
12701292 sb .append ("]; " );
12711293 BeanFactory parent = getParentBeanFactory ();
12721294 if (parent == null ) {
0 commit comments