{
Iterator<String> it = names.iterator();
while (it.hasNext())
{
final String possibility = it.next();
BeanDefinition beanDef = getBeanDefinition(
((AbstractApplicationContext)ctx).getBeanFactory(), possibility);
if (BeanFactoryUtils.isFactoryDereference(possibility) ||
possibility.startsWith("scopedTarget.") ||
(beanDef != null && !beanDef.isAutowireCandidate()))
{
it.remove();
}
}
}
if (names.isEmpty())
{
if (required)
{
throw new IllegalStateException("bean of type [" + clazz.getName() + "] not found");
}
return null;
}
else if (names.size() > 1)
{
if (ctx instanceof AbstractApplicationContext)
{
List<String> primaries = new ArrayList<String>();
for (String name : names)
{
BeanDefinition beanDef = getBeanDefinition(
((AbstractApplicationContext)ctx).getBeanFactory(), name);
if (beanDef instanceof AbstractBeanDefinition)
{
if (beanDef.isPrimary())
{
primaries.add(name);
}
}
}