@ -332,37 +332,38 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@@ -332,37 +332,38 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Override
@SuppressWarnings ( "unchecked" )
public < T > T getBean ( Class < T > requiredType , Object . . . args ) throws BeansException {
Assert . notNull ( requiredType , "Required type must not be null" ) ;
String [ ] bean Names = getBeanNamesForType ( requiredType ) ;
String [ ] candidate Names = getBeanNamesForType ( requiredType ) ;
if ( bean Names. length > 1 ) {
Array List< String > autowireCandidates = new ArrayList < String > ( ) ;
for ( String beanName : bean Names) {
if ( candidate Names. length > 1 ) {
List < String > autowireCandidates = new ArrayList < String > ( candidateNames . length ) ;
for ( String beanName : candidate Names) {
if ( ! containsBeanDefinition ( beanName ) | | getBeanDefinition ( beanName ) . isAutowireCandidate ( ) ) {
autowireCandidates . add ( beanName ) ;
}
}
if ( autowireCandidates . size ( ) > 0 ) {
bean Names = autowireCandidates . toArray ( new String [ autowireCandidates . size ( ) ] ) ;
candidate Names = autowireCandidates . toArray ( new String [ autowireCandidates . size ( ) ] ) ;
}
}
if ( bean Names. length = = 1 ) {
return getBean ( bean Names[ 0 ] , requiredType , args ) ;
if ( candidate Names. length = = 1 ) {
return getBean ( candidate Names[ 0 ] , requiredType , args ) ;
}
else if ( bean Names. length > 1 ) {
else if ( candidate Names. length > 1 ) {
Map < String , Object > candidates = new LinkedHashMap < String , Object > ( ) ;
for ( String beanName : bean Names) {
for ( String beanName : candidate Names) {
candidates . put ( beanName , getBean ( beanName , requiredType , args ) ) ;
}
String primaryCandidate = determinePrimaryCandidate ( candidates , requiredType ) ;
if ( primaryCandidate ! = null ) {
return getBean ( primaryCandidate , requiredType , args ) ;
return ( T ) candidates . get ( primaryCandidate ) ;
}
String priorityCandidate = determineHighestPriorityCandidate ( candidates , requiredType ) ;
if ( priorityCandidate ! = null ) {
return getBean ( priorityCandidate , requiredType , args ) ;
return ( T ) candidates . get ( priorityCandidate ) ;
}
throw new NoUniqueBeanDefinitionException ( requiredType , candidates . keySet ( ) ) ;
}
@ -1477,7 +1478,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@@ -1477,7 +1478,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
public DependencyObjectFactory ( DependencyDescriptor descriptor , String beanName ) {
this . descriptor = new DependencyDescriptor ( descriptor ) ;
this . descriptor . increaseNestingLevel ( ) ;
this . optional = this . descriptor . getDependencyType ( ) . equals ( javaUtilOptionalClass ) ;
this . optional = ( this . descriptor . getDependencyType ( ) = = javaUtilOptionalClass ) ;
this . beanName = beanName ;
}
@ -1541,7 +1542,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@@ -1541,7 +1542,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
if ( beanDefinition = = null ) {
return null ;
}
List < Object > sources = new ArrayList < Object > ( ) ;
List < Object > sources = new ArrayList < Object > ( 2 ) ;
Method factoryMethod = beanDefinition . getResolvedFactoryMethod ( ) ;
if ( factoryMethod ! = null ) {
sources . add ( factoryMethod ) ;