use of cn.taketoday.beans.factory.NoUniqueBeanDefinitionException in project today-framework by TAKETODAY.
the class ConstructorResolver method resolveAutowiredArgument.
/**
* Template method for resolving the specified argument which is supposed to be autowired.
*/
@Nullable
private Object resolveAutowiredArgument(MethodParameter param, String beanName, @Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter, boolean fallback) {
Class<?> paramType = param.getParameterType();
if (InjectionPoint.class.isAssignableFrom(paramType)) {
InjectionPoint injectionPoint = currentInjectionPoint.get();
if (injectionPoint == null) {
throw new IllegalStateException("No current InjectionPoint available for " + param);
}
return injectionPoint;
}
try {
DependencyResolvingContext context = new DependencyResolvingContext(param.getExecutable(), beanFactory, beanName);
context.setTypeConverter(typeConverter);
context.setDependentBeans(autowiredBeanNames);
return injector.resolveValue(new DependencyDescriptor(param, true), context);
} catch (NoUniqueBeanDefinitionException ex) {
throw ex;
} catch (NoSuchBeanDefinitionException ex) {
if (fallback) {
// for e.g. a vararg or a non-null List/Set/Map parameter.
if (paramType.isArray()) {
return Array.newInstance(paramType.getComponentType(), 0);
} else if (CollectionUtils.isApproximableCollectionType(paramType)) {
return CollectionUtils.createCollection(paramType, 0);
} else if (CollectionUtils.isApproximableMapType(paramType)) {
return CollectionUtils.createMap(paramType, 0);
}
}
throw ex;
}
}
use of cn.taketoday.beans.factory.NoUniqueBeanDefinitionException in project today-framework by TAKETODAY.
the class NoSuchBeanDefinitionFailureAnalyzerTests method failureAnalysisForMultipleBeans.
@Test
void failureAnalysisForMultipleBeans() {
FailureAnalysis analysis = analyzeFailure(new NoUniqueBeanDefinitionException(String.class, 2, "Test"));
assertThat(analysis).isNull();
}
use of cn.taketoday.beans.factory.NoUniqueBeanDefinitionException in project today-infrastructure by TAKETODAY.
the class NoSuchBeanDefinitionFailureAnalyzerTests method failureAnalysisForMultipleBeans.
@Test
void failureAnalysisForMultipleBeans() {
FailureAnalysis analysis = analyzeFailure(new NoUniqueBeanDefinitionException(String.class, 2, "Test"));
assertThat(analysis).isNull();
}
use of cn.taketoday.beans.factory.NoUniqueBeanDefinitionException in project today-infrastructure by TAKETODAY.
the class ConstructorResolver method resolveAutowiredArgument.
/**
* Template method for resolving the specified argument which is supposed to be autowired.
*/
@Nullable
private Object resolveAutowiredArgument(MethodParameter param, String beanName, @Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter, boolean fallback) {
Class<?> paramType = param.getParameterType();
if (InjectionPoint.class.isAssignableFrom(paramType)) {
InjectionPoint injectionPoint = currentInjectionPoint.get();
if (injectionPoint == null) {
throw new IllegalStateException("No current InjectionPoint available for " + param);
}
return injectionPoint;
}
try {
DependencyResolvingContext context = new DependencyResolvingContext(param.getExecutable(), beanFactory, beanName);
context.setTypeConverter(typeConverter);
context.setDependentBeans(autowiredBeanNames);
return injector.resolveValue(new DependencyDescriptor(param, true), context);
} catch (NoUniqueBeanDefinitionException ex) {
throw ex;
} catch (NoSuchBeanDefinitionException ex) {
if (fallback) {
// for e.g. a vararg or a non-null List/Set/Map parameter.
if (paramType.isArray()) {
return Array.newInstance(paramType.getComponentType(), 0);
} else if (CollectionUtils.isApproximableCollectionType(paramType)) {
return CollectionUtils.createCollection(paramType, 0);
} else if (CollectionUtils.isApproximableMapType(paramType)) {
return CollectionUtils.createMap(paramType, 0);
}
}
throw ex;
}
}
Aggregations