当前位置: 首页>>代码示例>>Java>>正文


Java DependencyDescriptor类代码示例

本文整理汇总了Java中org.springframework.beans.factory.config.DependencyDescriptor的典型用法代码示例。如果您正苦于以下问题:Java DependencyDescriptor类的具体用法?Java DependencyDescriptor怎么用?Java DependencyDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DependencyDescriptor类属于org.springframework.beans.factory.config包,在下文中一共展示了DependencyDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAutowireCandidate

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
/**
 * 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 && descriptor != null) {
		match = checkQualifiers(bdHolder, descriptor.getAnnotations());
		if (match) {
			MethodParameter methodParam = descriptor.getMethodParameter();
			if (methodParam != null) {
				Method method = methodParam.getMethod();
				if (method == null || void.class.equals(method.getReturnType())) {
					match = checkQualifiers(bdHolder, methodParam.getMethodAnnotations());
				}
			}
		}
	}
	return match;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:QualifierAnnotationAutowireCandidateResolver.java

示例2: getReturnTypeForFactoryMethod

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
protected ResolvableType getReturnTypeForFactoryMethod(RootBeanDefinition rbd, DependencyDescriptor descriptor) {
	// Should typically be set for any kind of factory method, since the BeanFactory
	// pre-resolves them before reaching out to the AutowireCandidateResolver...
	Class<?> preResolved = rbd.resolvedFactoryMethodReturnType;
	if (preResolved != null) {
		return ResolvableType.forClass(preResolved);
	}
	else {
		Method resolvedFactoryMethod = rbd.getResolvedFactoryMethod();
		if (resolvedFactoryMethod != null) {
			if (descriptor.getDependencyType().isAssignableFrom(resolvedFactoryMethod.getReturnType())) {
				// Only use factory method metadata if the return type is actually expressive enough
				// for our dependency. Otherwise, the returned instance type may have matched instead
				// in case of a singleton instance having been registered with the container already.
				return ResolvableType.forMethodReturnType(resolvedFactoryMethod);
			}
		}
		return null;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:GenericTypeAwareAutowireCandidateResolver.java

示例3: isAutowireCandidate

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
/**
 * 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);
	}
	else if (getParentBeanFactory() instanceof DefaultListableBeanFactory) {
		// No bean definition found in this factory -> delegate to parent.
		return ((DefaultListableBeanFactory) getParentBeanFactory()).isAutowireCandidate(beanName, descriptor, resolver);
	}
	else if (getParentBeanFactory() instanceof ConfigurableListableBeanFactory) {
		// If no DefaultListableBeanFactory, can't pass the resolver along.
		return ((ConfigurableListableBeanFactory) getParentBeanFactory()).isAutowireCandidate(beanName, descriptor);
	}
	else {
		return true;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:DefaultListableBeanFactory.java

示例4: resolveDependency

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
@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;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:DefaultListableBeanFactory.java

示例5: configureBeanGrid

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
@Bean
@Scope(scopeName = "prototype")
@SuppressWarnings("unchecked")
public <ITEM> Grid<ITEM> configureBeanGrid(DependencyDescriptor dependencyDescriptor) {
	logger.debug("Configuring Vaadin Grid as bean");

	long timestamp = System.currentTimeMillis();

	ResolvableType injectionPointType = dependencyDescriptor.getResolvableType();
	if (!injectionPointType.hasGenerics()) {
		throw new IllegalStateException("Grid injection point is expected to declare a static item type");
	}

	ResolvableType genericType = injectionPointType.getGeneric();
	Class<ITEM> itemType = (Class<ITEM>) genericType.resolve();

	logger.debug("Vaadin Grid will use " + itemType.getCanonicalName() + " as item type");

	Grid<ITEM> grid = configureGridInstance(itemType);
	long configTime = System.currentTimeMillis() - timestamp;
	logger.debug("Done configuring Grid for " + itemType.getName() + " in " + configTime + "ms");

	return grid;
}
 
开发者ID:peterl1084,项目名称:bean-grid,代码行数:25,代码来源:BeanGridConfiguration.java

示例6: isAutowireCandidate

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
/**
 * 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 && descriptor != null) {
		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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:QualifierAnnotationAutowireCandidateResolver.java

示例7: resolveDependency

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
@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;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:DefaultListableBeanFactory.java

示例8: determineAutowireCandidate

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:DefaultListableBeanFactory.java

示例9: testAutowireCandidateWithFieldDescriptor

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
@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));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:QualifierAnnotationAutowireBeanFactoryTests.java

示例10: testAutowireCandidateExplicitlyFalseWithFieldDescriptor

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
@Test
public void testAutowireCandidateExplicitlyFalseWithFieldDescriptor() throws Exception {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	ConstructorArgumentValues cavs = new ConstructorArgumentValues();
	cavs.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
	person.setAutowireCandidate(false);
	person.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
	lbf.registerBeanDefinition(JUERGEN, person);
	DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(
			QualifiedTestBean.class.getDeclaredField("qualified"), false);
	DependencyDescriptor nonqualifiedDescriptor = new DependencyDescriptor(
			QualifiedTestBean.class.getDeclaredField("nonqualified"), false);
	assertFalse(lbf.isAutowireCandidate(JUERGEN, null));
	assertFalse(lbf.isAutowireCandidate(JUERGEN, nonqualifiedDescriptor));
	assertFalse(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:QualifierAnnotationAutowireBeanFactoryTests.java

示例11: testAutowireCandidateWithShortClassName

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
@Test
public void testAutowireCandidateWithShortClassName() throws Exception {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	ConstructorArgumentValues cavs = new ConstructorArgumentValues();
	cavs.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
	person.addQualifier(new AutowireCandidateQualifier(ClassUtils.getShortName(TestQualifier.class)));
	lbf.registerBeanDefinition(JUERGEN, person);
	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));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:QualifierAnnotationAutowireBeanFactoryTests.java

示例12: testAutowireCandidateWithConstructorDescriptor

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
@Ignore
@Test
public void testAutowireCandidateWithConstructorDescriptor() 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);
	MethodParameter param = new MethodParameter(QualifiedTestBean.class.getDeclaredConstructor(Person.class), 0);
	DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(param, false);
	param.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
	assertEquals("tpb", param.getParameterName());
	assertTrue(lbf.isAutowireCandidate(JUERGEN, null));
	assertTrue(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor));
	assertFalse(lbf.isAutowireCandidate(MARK, qualifiedDescriptor));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:QualifierAnnotationAutowireBeanFactoryTests.java

示例13: testAutowireCandidateWithMultipleCandidatesDescriptor

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
@Test
public void testAutowireCandidateWithMultipleCandidatesDescriptor() 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);
	person2.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
	lbf.registerBeanDefinition(MARK, person2);
	DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(
			new MethodParameter(QualifiedTestBean.class.getDeclaredConstructor(Person.class), 0),
			false);
	assertTrue(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor));
	assertTrue(lbf.isAutowireCandidate(MARK, qualifiedDescriptor));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:QualifierAnnotationAutowireBeanFactoryTests.java

示例14: findAutowireCandidates

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
@Override
protected Map<String, Object> findAutowireCandidates(String beanName,
		Class requiredType,
		DependencyDescriptor descriptor) {
	Map<String, Object> tmp= super.findAutowireCandidates(beanName, requiredType,descriptor);
	Map<String, Object> result= new HashMap<String,Object>(); 
	for(Iterator<Entry<String,Object>> it=tmp.entrySet().iterator();it.hasNext();){
		Entry<String,Object> entry= it.next();
		String key= entry.getKey();
		Object value= entry.getValue();
		if(key.indexOf(Constants.FACTORY_SEGMENT)>0){
			result.put(key.split(Constants.FACTORY_SEGMENT)[1], value);
			continue;
		}
		result.put(key, value);
	}		
	return result;
}
 
开发者ID:balancebeam,项目名称:puzzle,代码行数:19,代码来源:PluginListableBeanFactory.java

示例15: resolveDependency

import org.springframework.beans.factory.config.DependencyDescriptor; //导入依赖的package包/类
@Override
public Object resolveDependency(DependencyDescriptor descriptor, String beanName,
                                Set<String> autowiredBeanNames,
                                TypeConverter typeConverter) throws BeansException {
    if (descriptor == null
            || descriptor.getField() == null
            || !descriptor.getField().getType().equals(Ignite.class))
        return super.resolveDependency(descriptor, beanName,
                autowiredBeanNames, typeConverter);
    else {
        if (configuration == null)
            configuration = new IgniteSpringBootConfiguration(
                    createBean(DefaultIgniteProperties.class));
        return configuration.getIgnite(
                descriptor.getField().getAnnotationsByType(IgniteResource.class));
    }
}
 
开发者ID:minlia,项目名称:ignite-spring-boot,代码行数:18,代码来源:IgniteBeanFactory.java


注:本文中的org.springframework.beans.factory.config.DependencyDescriptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。