@ -43,6 +43,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.concurrent.ConcurrentHashMap ;
import javax.inject.Provider ;
import javax.inject.Provider ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.BeansException ;
import org.springframework.beans.BeansException ;
import org.springframework.beans.TypeConverter ;
import org.springframework.beans.TypeConverter ;
import org.springframework.beans.factory.BeanCreationException ;
import org.springframework.beans.factory.BeanCreationException ;
@ -256,6 +257,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
/ * *
/ * *
* Set a { @link java . util . Comparator } for dependency Lists and arrays .
* Set a { @link java . util . Comparator } for dependency Lists and arrays .
* @since 4 . 0
* @see org . springframework . core . OrderComparator
* @see org . springframework . core . OrderComparator
* @see org . springframework . core . annotation . AnnotationAwareOrderComparator
* @see org . springframework . core . annotation . AnnotationAwareOrderComparator
* /
* /
@ -265,6 +267,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
/ * *
/ * *
* Return the dependency comparator for this BeanFactory ( may be { @code null } .
* Return the dependency comparator for this BeanFactory ( may be { @code null } .
* @since 4 . 0
* /
* /
public Comparator < Object > getDependencyComparator ( ) {
public Comparator < Object > getDependencyComparator ( ) {
return this . dependencyComparator ;
return this . dependencyComparator ;
@ -279,11 +282,10 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
Assert . notNull ( autowireCandidateResolver , "AutowireCandidateResolver must not be null" ) ;
Assert . notNull ( autowireCandidateResolver , "AutowireCandidateResolver must not be null" ) ;
if ( autowireCandidateResolver instanceof BeanFactoryAware ) {
if ( autowireCandidateResolver instanceof BeanFactoryAware ) {
if ( System . getSecurityManager ( ) ! = null ) {
if ( System . getSecurityManager ( ) ! = null ) {
final BeanFactory target = this ;
AccessController . doPrivileged ( new PrivilegedAction < Object > ( ) {
AccessController . doPrivileged ( new PrivilegedAction < Object > ( ) {
@Override
@Override
public Object run ( ) {
public Object run ( ) {
( ( BeanFactoryAware ) autowireCandidateResolver ) . setBeanFactory ( target ) ;
( ( BeanFactoryAware ) autowireCandidateResolver ) . setBeanFactory ( DefaultListableBeanFactory . this ) ;
return null ;
return null ;
}
}
} , getAccessControlContext ( ) ) ;
} , getAccessControlContext ( ) ) ;
@ -310,7 +312,10 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
DefaultListableBeanFactory otherListableFactory = ( DefaultListableBeanFactory ) otherFactory ;
DefaultListableBeanFactory otherListableFactory = ( DefaultListableBeanFactory ) otherFactory ;
this . allowBeanDefinitionOverriding = otherListableFactory . allowBeanDefinitionOverriding ;
this . allowBeanDefinitionOverriding = otherListableFactory . allowBeanDefinitionOverriding ;
this . allowEagerClassLoading = otherListableFactory . allowEagerClassLoading ;
this . allowEagerClassLoading = otherListableFactory . allowEagerClassLoading ;
this . autowireCandidateResolver = otherListableFactory . autowireCandidateResolver ;
this . dependencyComparator = otherListableFactory . dependencyComparator ;
// A clone of the AutowireCandidateResolver since it is potentially BeanFactoryAware...
setAutowireCandidateResolver ( BeanUtils . instantiateClass ( getAutowireCandidateResolver ( ) . getClass ( ) ) ) ;
// Make resolvable dependencies (e.g. ResourceLoader) available here as well...
this . resolvableDependencies . putAll ( otherListableFactory . resolvableDependencies ) ;
this . resolvableDependencies . putAll ( otherListableFactory . resolvableDependencies ) ;
}
}
}
}
@ -357,7 +362,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@Override
@Override
public String [ ] getBeanDefinitionNames ( ) {
public String [ ] getBeanDefinitionNames ( ) {
if ( this . frozenBeanDefinitionNames ! = null ) {
if ( this . frozenBeanDefinitionNames ! = null ) {
return this . frozenBeanDefinitionNames ;
return this . frozenBeanDefinitionNames . clone ( ) ;
}
}
else {
else {
return StringUtils . toStringArray ( this . beanDefinitionNames ) ;
return StringUtils . toStringArray ( this . beanDefinitionNames ) ;
@ -1256,8 +1261,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
addCandidateEntry ( result , candidateName , descriptor , requiredType ) ;
addCandidateEntry ( result , candidateName , descriptor , requiredType ) ;
}
}
}
}
if ( result . isEmpty ( ) ) {
if ( result . isEmpty ( ) & & ! ( descriptor instanceof MultiElementDependencyDescriptor ) ) {
// Consider self references before as a final pass
// Consider self references as a final pass...
// but not as collection elements, just for direct dependency declarations.
for ( String candidateName : candidateNames ) {
for ( String candidateName : candidateNames ) {
if ( isSelfReference ( beanName , candidateName ) & & isAutowireCandidate ( candidateName , fallbackDescriptor ) ) {
if ( isSelfReference ( beanName , candidateName ) & & isAutowireCandidate ( candidateName , fallbackDescriptor ) ) {
addCandidateEntry ( result , candidateName , descriptor , requiredType ) ;
addCandidateEntry ( result , candidateName , descriptor , requiredType ) ;
@ -1466,10 +1472,10 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
Class < ? > targetType = mbd . getTargetType ( ) ;
Class < ? > targetType = mbd . getTargetType ( ) ;
if ( targetType ! = null & & type . isAssignableFrom ( targetType ) & &
if ( targetType ! = null & & type . isAssignableFrom ( targetType ) & &
isAutowireCandidate ( beanName , mbd , descriptor , getAutowireCandidateResolver ( ) ) ) {
isAutowireCandidate ( beanName , mbd , descriptor , getAutowireCandidateResolver ( ) ) ) {
// Probably a poxy interfering with target type match -> throw meaningful exception.
// Probably a pr oxy interfering with target type match -> throw meaningful exception.
Object beanInstance = getSingleton ( beanName , false ) ;
Object beanInstance = getSingleton ( beanName , false ) ;
Class < ? > beanType = ( beanInstance ! = null ? beanInstance . getClass ( ) : predictBeanType ( beanName , mbd ) ) ;
Class < ? > beanType = ( beanInstance ! = null ? beanInstance . getClass ( ) : predictBeanType ( beanName , mbd ) ) ;
if ( type ! = beanType ) {
if ( ! type . isAssignableFrom ( ( beanType ) ) ) {
throw new BeanNotOfRequiredTypeException ( beanName , type , beanType ) ;
throw new BeanNotOfRequiredTypeException ( beanName , type , beanType ) ;
}
}
}
}