Java Code Examples for org.springframework.beans.factory.config.DependencyDescriptor

The following examples show how to use org.springframework.beans.factory.config.DependencyDescriptor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected Map<String, Object> findAutowireCandidates(String beanName, Class<?> requiredType,
                                                     DependencyDescriptor descriptor) {

    if (!requiredType.equals(Provider.class)) {
        return super.findAutowireCandidates(beanName, requiredType, descriptor);
    }

    DependencyDescriptor providedDescriptor = new DependencyDescriptor(descriptor);
    providedDescriptor.increaseNestingLevel();
    Class<?> type = providedDescriptor.getDependencyType();
    Set<String> candidates = findAutowireCandidates(beanName, type, providedDescriptor).keySet();
    return candidates.stream()
            .collect(toMap(Function.identity(), name -> new DependencyProvider(this, descriptor, name)));

}
 
Example 2
Source Project: blog_demos   Source File: DefaultListableBeanFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object resolveDependency(DependencyDescriptor descriptor, String beanName,
		Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {

	descriptor.initParameterNameDiscovery(getParameterNameDiscoverer());
	if (descriptor.getDependencyType().equals(ObjectFactory.class)) {
		return new DependencyObjectFactory(descriptor, beanName);
	}
	else if (descriptor.getDependencyType().equals(javaxInjectProviderClass)) {
		return new DependencyProviderFactory().createDependencyProvider(descriptor, beanName);
	}
	else {
		Object result = getAutowireCandidateResolver().getLazyResolutionProxyIfNecessary(descriptor, beanName);
		if (result == null) {
			result = doResolveDependency(descriptor, beanName, autowiredBeanNames, typeConverter);
		}
		return result;
	}
}
 
Example 3
/**
 * Determine whether the provided bean definition is an autowire candidate.
 * <p>To be considered a candidate the bean's <em>autowire-candidate</em>
 * attribute must not have been set to 'false'. Also, if an annotation on
 * the field or parameter to be autowired is recognized by this bean factory
 * as a <em>qualifier</em>, the bean must 'match' against the annotation as
 * well as any attributes it may contain. The bean definition must contain
 * the same qualifier or match by meta attributes. A "value" attribute will
 * fallback to match against the bean name or an alias if a qualifier or
 * attribute does not match.
 * @see Qualifier
 */
@Override
public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) {
	boolean match = super.isAutowireCandidate(bdHolder, descriptor);
	if (match) {
		match = checkQualifiers(bdHolder, descriptor.getAnnotations());
		if (match) {
			MethodParameter methodParam = descriptor.getMethodParameter();
			if (methodParam != null) {
				Method method = methodParam.getMethod();
				if (method == null || void.class == method.getReturnType()) {
					match = checkQualifiers(bdHolder, methodParam.getMethodAnnotations());
				}
			}
		}
	}
	return match;
}
 
Example 4
@Ignore
@Test
public void testAutowireCandidateWithFieldDescriptor() throws Exception {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	person1.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
	lbf.registerBeanDefinition(JUERGEN, person1);
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue(MARK);
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	lbf.registerBeanDefinition(MARK, person2);
	DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(
			QualifiedTestBean.class.getDeclaredField("qualified"), false);
	DependencyDescriptor nonqualifiedDescriptor = new DependencyDescriptor(
			QualifiedTestBean.class.getDeclaredField("nonqualified"), false);
	assertTrue(lbf.isAutowireCandidate(JUERGEN, null));
	assertTrue(lbf.isAutowireCandidate(JUERGEN, nonqualifiedDescriptor));
	assertTrue(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor));
	assertTrue(lbf.isAutowireCandidate(MARK, null));
	assertTrue(lbf.isAutowireCandidate(MARK, nonqualifiedDescriptor));
	assertFalse(lbf.isAutowireCandidate(MARK, qualifiedDescriptor));
}
 
Example 5
@Override
public Object resolveDependency(DependencyDescriptor descriptor, String beanName,
		Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {

	descriptor.initParameterNameDiscovery(getParameterNameDiscoverer());
	if (descriptor.getDependencyType().equals(javaUtilOptionalClass)) {
		return new OptionalDependencyFactory().createOptionalDependency(descriptor, beanName);
	}
	else if (ObjectFactory.class == descriptor.getDependencyType()) {
		return new DependencyObjectFactory(descriptor, beanName);
	}
	else if (javaxInjectProviderClass == descriptor.getDependencyType()) {
		return new DependencyProviderFactory().createDependencyProvider(descriptor, beanName);
	}
	else {
		Object result = getAutowireCandidateResolver().getLazyResolutionProxyIfNecessary(descriptor, beanName);
		if (result == null) {
			result = doResolveDependency(descriptor, beanName, autowiredBeanNames, typeConverter);
		}
		return result;
	}
}
 
Example 6
/**
 * Determine the autowire candidate in the given set of beans.
 * <p>Looks for {@code @Primary} and {@code @Priority} (in that order).
 * @param candidateBeans a Map of candidate names and candidate instances
 * that match the required type, as returned by {@link #findAutowireCandidates}
 * @param descriptor the target dependency to match against
 * @return the name of the autowire candidate, or {@code null} if none found
 */
protected String determineAutowireCandidate(Map<String, Object> candidateBeans, DependencyDescriptor descriptor) {
	Class<?> requiredType = descriptor.getDependencyType();
	String primaryCandidate = determinePrimaryCandidate(candidateBeans, requiredType);
	if (primaryCandidate != null) {
		return primaryCandidate;
	}
	String priorityCandidate = determineHighestPriorityCandidate(candidateBeans, requiredType);
	if (priorityCandidate != null) {
		return priorityCandidate;
	}
	// Fallback
	for (Map.Entry<String, Object> entry : candidateBeans.entrySet()) {
		String candidateBeanName = entry.getKey();
		Object beanInstance = entry.getValue();
		if ((beanInstance != null && this.resolvableDependencies.containsValue(beanInstance)) ||
				matchesBeanName(candidateBeanName, descriptor.getDependencyName())) {
			return candidateBeanName;
		}
	}
	return null;
}
 
Example 7
Source Project: spring-analysis-note   Source File: DefaultListableBeanFactory.java    License: MIT License 6 votes vote down vote up
/**
 * Determine the autowire candidate in the given set of beans.
 * <p>Looks for {@code @Primary} and {@code @Priority} (in that order).
 * @param candidates a Map of candidate names and candidate instances
 * that match the required type, as returned by {@link #findAutowireCandidates}
 * @param descriptor the target dependency to match against
 * @return the name of the autowire candidate, or {@code null} if none found
 */
@Nullable
protected String determineAutowireCandidate(Map<String, Object> candidates, DependencyDescriptor descriptor) {
	Class<?> requiredType = descriptor.getDependencyType();
	String primaryCandidate = determinePrimaryCandidate(candidates, requiredType);
	if (primaryCandidate != null) {
		return primaryCandidate;
	}
	String priorityCandidate = determineHighestPriorityCandidate(candidates, requiredType);
	if (priorityCandidate != null) {
		return priorityCandidate;
	}
	// Fallback
	for (Map.Entry<String, Object> entry : candidates.entrySet()) {
		String candidateName = entry.getKey();
		Object beanInstance = entry.getValue();
		if ((beanInstance != null && this.resolvableDependencies.containsValue(beanInstance)) ||
				matchesBeanName(candidateName, descriptor.getDependencyName())) {
			return candidateName;
		}
	}
	return null;
}
 
Example 8
@Override
public Object getIfUnique() throws BeansException {
	DependencyDescriptor descriptorToUse = new DependencyDescriptor(descriptor) {
		@Override
		public boolean isRequired() {
			return false;
		}
		@Override
		public Object resolveNotUnique(Class<?> type, Map<String, Object> matchingBeans) {
			return null;
		}
	};
	if (this.optional) {
		return new OptionalDependencyFactory().createOptionalDependency(descriptorToUse, this.beanName);
	}
	else {
		return doResolveDependency(descriptorToUse, this.beanName, null, null);
	}
}
 
Example 9
Source Project: java-technology-stack   Source File: DefaultListableBeanFactory.java    License: MIT License 6 votes vote down vote up
@Override
@Nullable
public Object getIfUnique() throws BeansException {
	DependencyDescriptor descriptorToUse = new DependencyDescriptor(this.descriptor) {
		@Override
		public boolean isRequired() {
			return false;
		}
		@Override
		@Nullable
		public Object resolveNotUnique(ResolvableType type, Map<String, Object> matchingBeans) {
			return null;
		}
	};
	if (this.optional) {
		return createOptionalDependency(descriptorToUse, this.beanName);
	}
	else {
		return doResolveDependency(descriptorToUse, this.beanName, null, null);
	}
}
 
Example 10
Source Project: spring-analysis-note   Source File: DefaultListableBeanFactory.java    License: MIT License 6 votes vote down vote up
@Override
@Nullable
public Object getIfUnique() throws BeansException {
	DependencyDescriptor descriptorToUse = new DependencyDescriptor(this.descriptor) {
		@Override
		public boolean isRequired() {
			return false;
		}
		@Override
		@Nullable
		public Object resolveNotUnique(ResolvableType type, Map<String, Object> matchingBeans) {
			return null;
		}
	};
	if (this.optional) {
		return createOptionalDependency(descriptorToUse, this.beanName);
	}
	else {
		return doResolveDependency(descriptorToUse, this.beanName, null, null);
	}
}
 
Example 11
Source Project: java-technology-stack   Source File: DefaultListableBeanFactory.java    License: MIT License 6 votes vote down vote up
@Override
@Nullable
public Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName,
		@Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException {

	descriptor.initParameterNameDiscovery(getParameterNameDiscoverer());
	if (Optional.class == descriptor.getDependencyType()) {
		return createOptionalDependency(descriptor, requestingBeanName);
	}
	else if (ObjectFactory.class == descriptor.getDependencyType() ||
			ObjectProvider.class == descriptor.getDependencyType()) {
		return new DependencyObjectProvider(descriptor, requestingBeanName);
	}
	else if (javaxInjectProviderClass == descriptor.getDependencyType()) {
		return new Jsr330Factory().createDependencyProvider(descriptor, requestingBeanName);
	}
	else {
		Object result = getAutowireCandidateResolver().getLazyResolutionProxyIfNecessary(
				descriptor, requestingBeanName);
		if (result == null) {
			result = doResolveDependency(descriptor, requestingBeanName, autowiredBeanNames, typeConverter);
		}
		return result;
	}
}
 
Example 12
Source Project: spring-analysis-note   Source File: ParameterResolutionTests.java    License: MIT License 6 votes vote down vote up
@Test
public void resolveDependencyForAnnotatedParametersInTopLevelClassConstructor() throws Exception {
	Constructor<?> constructor = AutowirableClass.class.getConstructor(String.class, String.class, String.class, String.class);

	AutowireCapableBeanFactory beanFactory = mock(AutowireCapableBeanFactory.class);
	// Configure the mocked BeanFactory to return the DependencyDescriptor for convenience and
	// to avoid using an ArgumentCaptor.
	given(beanFactory.resolveDependency(any(), isNull())).willAnswer(invocation -> invocation.getArgument(0));

	Parameter[] parameters = constructor.getParameters();
	for (int parameterIndex = 0; parameterIndex < parameters.length; parameterIndex++) {
		Parameter parameter = parameters[parameterIndex];
		DependencyDescriptor intermediateDependencyDescriptor = (DependencyDescriptor) ParameterResolutionDelegate.resolveDependency(
				parameter, parameterIndex, AutowirableClass.class, beanFactory);
		assertEquals(constructor, intermediateDependencyDescriptor.getAnnotatedElement());
		assertEquals(parameter, intermediateDependencyDescriptor.getMethodParameter().getParameter());
	}
}
 
Example 13
@Ignore
@Test
public void testAutowireCandidateWithFieldDescriptor() throws Exception {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	person1.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
	lbf.registerBeanDefinition(JUERGEN, person1);
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue(MARK);
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	lbf.registerBeanDefinition(MARK, person2);
	DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(
			QualifiedTestBean.class.getDeclaredField("qualified"), false);
	DependencyDescriptor nonqualifiedDescriptor = new DependencyDescriptor(
			QualifiedTestBean.class.getDeclaredField("nonqualified"), false);
	assertTrue(lbf.isAutowireCandidate(JUERGEN, null));
	assertTrue(lbf.isAutowireCandidate(JUERGEN, nonqualifiedDescriptor));
	assertTrue(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor));
	assertTrue(lbf.isAutowireCandidate(MARK, null));
	assertTrue(lbf.isAutowireCandidate(MARK, nonqualifiedDescriptor));
	assertFalse(lbf.isAutowireCandidate(MARK, qualifiedDescriptor));
}
 
Example 14
/**
 * Determine the autowire candidate in the given set of beans.
 * <p>Looks for {@code @Primary} and {@code @Priority} (in that order).
 * @param candidates a Map of candidate names and candidate instances
 * that match the required type, as returned by {@link #findAutowireCandidates}
 * @param descriptor the target dependency to match against
 * @return the name of the autowire candidate, or {@code null} if none found
 */
protected String determineAutowireCandidate(Map<String, Object> candidates, DependencyDescriptor descriptor) {
	Class<?> requiredType = descriptor.getDependencyType();
	String primaryCandidate = determinePrimaryCandidate(candidates, requiredType);
	if (primaryCandidate != null) {
		return primaryCandidate;
	}
	String priorityCandidate = determineHighestPriorityCandidate(candidates, requiredType);
	if (priorityCandidate != null) {
		return priorityCandidate;
	}
	// Fallback
	for (Map.Entry<String, Object> entry : candidates.entrySet()) {
		String candidateName = entry.getKey();
		Object beanInstance = entry.getValue();
		if ((beanInstance != null && this.resolvableDependencies.containsValue(beanInstance)) ||
				matchesBeanName(candidateName, descriptor.getDependencyName())) {
			return candidateName;
		}
	}
	return null;
}
 
Example 15
@Override
   public boolean isAutowireCandidate(String beanName, DependencyDescriptor descriptor)
		throws NoSuchBeanDefinitionException {

	// Consider FactoryBeans as autowiring candidates.
	boolean isFactoryBean = (descriptor != null && descriptor.getDependencyType() != null &&
			FactoryBean.class.isAssignableFrom(descriptor.getDependencyType()));
	if (isFactoryBean) {
		beanName = BeanFactoryUtils.transformedBeanName(beanName);
	}

	if (containsBeanDefinition(beanName)) {
		return isAutowireCandidate(beanName, getMergedLocalBeanDefinition(beanName), descriptor);
	}
	else if (containsSingleton(beanName)) {
		return isAutowireCandidate(beanName, new RootBeanDefinition(getType(beanName)), descriptor);
	}
	else if (getParentBeanFactory() instanceof ConfigurableListableBeanFactory) {
		// No bean definition found in this factory -> delegate to parent.
		return ((ConfigurableListableBeanFactory) getParentBeanFactory()).isAutowireCandidate(beanName, descriptor);
	}
	else {
		return true;
	}
}
 
Example 16
Source Project: cuba   Source File: CubaDefaultListableBeanFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object resolveDependency(DependencyDescriptor descriptor, String beanName, Set<String> autowiredBeanNames,
                                TypeConverter typeConverter) throws BeansException {
    Field field = descriptor.getField();

    if (field != null && Logger.class == descriptor.getDependencyType()) {
        return LoggerFactory.getLogger(getDeclaringClass(descriptor));
    }

    if (field != null && Config.class.isAssignableFrom(field.getType())) {
        return getConfig(field.getType());
    }
    MethodParameter methodParam = descriptor.getMethodParameter();
    if (methodParam != null && Config.class.isAssignableFrom(methodParam.getParameterType())) {
        return getConfig(methodParam.getParameterType());
    }
    return super.resolveDependency(descriptor, beanName, autowiredBeanNames, typeConverter);
}
 
Example 17
Source Project: java-technology-stack   Source File: DefaultListableBeanFactory.java    License: MIT License 6 votes vote down vote up
/**
 * Determine whether the specified bean definition qualifies as an autowire candidate,
 * to be injected into other beans which declare a dependency of matching type.
 * @param beanName the name of the bean definition to check
 * @param descriptor the descriptor of the dependency to resolve
 * @param resolver the AutowireCandidateResolver to use for the actual resolution algorithm
 * @return whether the bean should be considered as autowire candidate
 */
protected boolean isAutowireCandidate(String beanName, DependencyDescriptor descriptor, AutowireCandidateResolver resolver)
		throws NoSuchBeanDefinitionException {

	String beanDefinitionName = BeanFactoryUtils.transformedBeanName(beanName);
	if (containsBeanDefinition(beanDefinitionName)) {
		return isAutowireCandidate(beanName, getMergedLocalBeanDefinition(beanDefinitionName), descriptor, resolver);
	}
	else if (containsSingleton(beanName)) {
		return isAutowireCandidate(beanName, new RootBeanDefinition(getType(beanName)), descriptor, resolver);
	}

	BeanFactory parent = getParentBeanFactory();
	if (parent instanceof DefaultListableBeanFactory) {
		// No bean definition found in this factory -> delegate to parent.
		return ((DefaultListableBeanFactory) parent).isAutowireCandidate(beanName, descriptor, resolver);
	}
	else if (parent instanceof ConfigurableListableBeanFactory) {
		// If no DefaultListableBeanFactory, can't pass the resolver along.
		return ((ConfigurableListableBeanFactory) parent).isAutowireCandidate(beanName, descriptor);
	}
	else {
		return true;
	}
}
 
Example 18
/**
 * Determine whether the specified bean definition qualifies as an autowire candidate,
 * to be injected into other beans which declare a dependency of matching type.
 * @param beanName the name of the bean definition to check
 * @param mbd the merged bean definition to check
 * @param descriptor the descriptor of the dependency to resolve
 * @param resolver the AutowireCandidateResolver to use for the actual resolution algorithm
 * @return whether the bean should be considered as autowire candidate
 */
protected boolean isAutowireCandidate(String beanName, RootBeanDefinition mbd,
		DependencyDescriptor descriptor, AutowireCandidateResolver resolver) {

	String beanDefinitionName = BeanFactoryUtils.transformedBeanName(beanName);
	resolveBeanClass(mbd, beanDefinitionName);
	if (mbd.isFactoryMethodUnique) {
		boolean resolve;
		synchronized (mbd.constructorArgumentLock) {
			resolve = (mbd.resolvedConstructorOrFactoryMethod == null);
		}
		if (resolve) {
			new ConstructorResolver(this).resolveFactoryMethodIfPossible(mbd);
		}
	}
	return resolver.isAutowireCandidate(
			new BeanDefinitionHolder(mbd, beanName, getAliases(beanDefinitionName)), descriptor);
}
 
Example 19
/**
 * Build a DependencyDescriptor for the underlying field/method.
 */
public final DependencyDescriptor getDependencyDescriptor() {
	if (this.isField) {
		return new LookupDependencyDescriptor((Field) this.member, this.lookupType);
	}
	else {
		return new LookupDependencyDescriptor((Method) this.member, this.lookupType);
	}
}
 
Example 20
/**
 * Resolve the specified cached method argument or field value.
 */
@Nullable
private Object resolvedCachedArgument(@Nullable String beanName, @Nullable Object cachedArgument) {
	if (cachedArgument instanceof DependencyDescriptor) {
		DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument;
		Assert.state(this.beanFactory != null, "No BeanFactory available");
		return this.beanFactory.resolveDependency(descriptor, beanName, null, null);
	}
	else {
		return cachedArgument;
	}
}
 
Example 21
/**
 * Determine whether the given dependency declares an autowired annotation,
 * checking its required flag.
 * @see Autowired#required()
 */
@Override
public boolean isRequired(DependencyDescriptor descriptor) {
	if (!super.isRequired(descriptor)) {
		return false;
	}
	Autowired autowired = descriptor.getAnnotation(Autowired.class);
	return (autowired == null || autowired.required());
}
 
Example 22
@Test
public void testAutowireCandidateExplicitlyFalseWithIrrelevantDescriptor() throws Exception {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	ConstructorArgumentValues cavs = new ConstructorArgumentValues();
	cavs.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition rbd = new RootBeanDefinition(Person.class, cavs, null);
	rbd.setAutowireCandidate(false);
	lbf.registerBeanDefinition(JUERGEN, rbd);
	assertFalse(lbf.isAutowireCandidate(JUERGEN, null));
	assertFalse(lbf.isAutowireCandidate(JUERGEN,
			new DependencyDescriptor(Person.class.getDeclaredField("name"), false)));
	assertFalse(lbf.isAutowireCandidate(JUERGEN,
			new DependencyDescriptor(Person.class.getDeclaredField("name"), true)));
}
 
Example 23
Source Project: tutorials   Source File: ParameterAutowireUtils.java    License: MIT License 5 votes vote down vote up
public static Object resolveDependency(Parameter parameter, Class<?> containingClass, ApplicationContext applicationContext) {

        boolean required = findMergedAnnotation(parameter, Autowired.class).map(Autowired::required)
            .orElse(true);
        MethodParameter methodParameter = (parameter.getDeclaringExecutable() instanceof Method ? MethodParameterFactory.createSynthesizingMethodParameter(parameter) : MethodParameterFactory.createMethodParameter(parameter));
        DependencyDescriptor descriptor = new DependencyDescriptor(methodParameter, required);
        descriptor.setContainingClass(containingClass);

        return applicationContext.getAutowireCapableBeanFactory()
            .resolveDependency(descriptor, null);
    }
 
Example 24
/**
 * Resolve the specified cached method argument or field value.
 */
private Object resolvedCachedArgument(String beanName, Object cachedArgument) {
	if (cachedArgument instanceof DependencyDescriptor) {
		DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument;
		return this.beanFactory.resolveDependency(descriptor, beanName, null, null);
	}
	else {
		return cachedArgument;
	}
}
 
Example 25
/**
 * Raise a NoSuchBeanDefinitionException for an unresolvable dependency.
 */
private void raiseNoSuchBeanDefinitionException(
		Class<?> type, String dependencyDescription, DependencyDescriptor descriptor)
		throws NoSuchBeanDefinitionException {

	throw new NoSuchBeanDefinitionException(type, dependencyDescription,
			"expected at least 1 bean which qualifies as autowire candidate for this dependency. " +
			"Dependency annotations: " + ObjectUtils.nullSafeToString(descriptor.getAnnotations()));
}
 
Example 26
@Override
public Object resolveBeanByName(String name, DependencyDescriptor descriptor) {
	InjectionPoint previousInjectionPoint = ConstructorResolver.setCurrentInjectionPoint(descriptor);
	try {
		return getBean(name, descriptor.getDependencyType());
	}
	finally {
		ConstructorResolver.setCurrentInjectionPoint(previousInjectionPoint);
	}
}
 
Example 27
/**
 * Determine whether the given dependency declares an autowired annotation,
 * checking its required flag.
 * @see Autowired#required()
 */
@Override
public boolean isRequired(DependencyDescriptor descriptor) {
	if (!super.isRequired(descriptor)) {
		return false;
	}
	Autowired autowired = descriptor.getAnnotation(Autowired.class);
	return (autowired == null || autowired.required());
}
 
Example 28
@Override
public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) {
	if (!super.isAutowireCandidate(bdHolder, descriptor)) {
		// If explicitly false, do not proceed with any other checks...
		return false;
	}
	return checkGenericTypeMatch(bdHolder, descriptor);
}
 
Example 29
Source Project: java-technology-stack   Source File: DefaultListableBeanFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Raise a NoSuchBeanDefinitionException or BeanNotOfRequiredTypeException
 * for an unresolvable dependency.
 */
private void raiseNoMatchingBeanFound(
		Class<?> type, ResolvableType resolvableType, DependencyDescriptor descriptor) throws BeansException {

	checkBeanNotOfRequiredType(type, descriptor);

	throw new NoSuchBeanDefinitionException(resolvableType,
			"expected at least 1 bean which qualifies as autowire candidate. " +
			"Dependency annotations: " + ObjectUtils.nullSafeToString(descriptor.getAnnotations()));
}
 
Example 30
@Override
   public Object resolveDependency(DependencyDescriptor descriptor, String beanName,
		Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException  {

	descriptor.initParameterNameDiscovery(getParameterNameDiscoverer());
	if (descriptor.getDependencyType().equals(ObjectFactory.class)) {
		return new DependencyObjectFactory(descriptor, beanName);
	}
	else if (descriptor.getDependencyType().equals(javaxInjectProviderClass)) {
		return new DependencyProviderFactory().createDependencyProvider(descriptor, beanName);
	}
	else {
		return doResolveDependency(descriptor, descriptor.getDependencyType(), beanName, autowiredBeanNames, typeConverter);
	}
}