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


Java BeanDefinitionHolder类代码示例

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


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

示例1: decorate

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {

    // 设置bean scope为version-refresh
    definition.getBeanDefinition().setScope(VersionRefreshScope.SCOPE_NAME);

    String[] dependsOn = null;
    if (node instanceof Element) {
        Element ele = (Element) node;
        if (ele.hasAttribute(DEPENDS_ON)) {
            dependsOn = StringUtils.tokenizeToStringArray(ele.getAttribute(DEPENDS_ON), ",");
        }
    }

    // 注册属性依赖
    DependencyConfigUtils.registerDependency(parserContext.getRegistry(), definition.getBeanName(), dependsOn);

    return definition;
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:20,代码来源:VersionRefreshBeanDefinitionDecorator.java

示例2: decorate

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    String propertyName = null;
    String converterClassName = null;
    if (node instanceof Element) {
        Element ele = (Element) node;
        if (ele.hasAttribute(PROPERTY_NAME)) {
            propertyName = ele.getAttribute(PROPERTY_NAME);
        }
        if (ele.hasAttribute(CONVERTER)) {
            converterClassName = ele.getAttribute(CONVERTER);
        }
    }

    // 为配置bean设置factory method
    Class<?> converterType = null;
    if (StringUtils.isNotEmpty(converterClassName)) {
        converterType = ClassUtils.resolveClassName(converterClassName, parserContext.getReaderContext().getBeanClassLoader());
    }
    ConfigBeanConfigUtils.setConfigBeanFactoryMethod(parserContext.getRegistry(),
            definition.getBeanName(), definition.getBeanDefinition(), propertyName, converterType);

    // 注册属性依赖
    DependencyConfigUtils.registerDependency(parserContext.getRegistry(), definition.getBeanName(), new String[]{propertyName});

    return definition;
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:28,代码来源:ConfigBeanBeanDefinitionDecorator.java

示例3: addRefIfNeeded

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
private void addRefIfNeeded(Object v, List<String> refs) {
         if(v == null) return;
         
         if(v instanceof RuntimeBeanReference) {
            RuntimeBeanReference r = (RuntimeBeanReference)v;
            String name = r.getBeanName();
            
            addRefIfNeeded(name, refs);
            
            if(name == null || name.length() == 0) {
               System.err.println("Warning - empty reference " + r);
            }
         } else if(v instanceof BeanDefinitionHolder) {
            // Nested bean definition
            BeanDefinitionHolder bdh = (BeanDefinitionHolder)v;
            processBeanDefinition(bdh.getBeanName(), bdh.getBeanDefinition());
         } else if(v instanceof ManagedList<?>) {
            ManagedList<?> ml = (ManagedList<?>)v;
            for(Object le : ml) {
               addRefIfNeeded(le, refs);
            }
//       } else {
//          System.err.println(v.getClass());
         }
      }
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:26,代码来源:ContextDependencyLister.java

示例4: parseRefOrBean

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
private Optional<RuntimeBeanReference> parseRefOrBean(Element elem, ParserContext ctx) {
    if (elem != null) {
        String ref = elem.getAttribute("ref").trim();

        Element beanEl = getChildElementByTagName(elem, "bean");

        if (!ref.isEmpty() && beanEl != null) {
            String name = elem.getLocalName();

            ctx.getReaderContext().error('<' + name + ">'s 'ref' attribute can't be mixed with nested <bean> element.", elem);
        } else if (!ref.isEmpty()) {
            return Optional.of(new RuntimeBeanReference(ref));
        } else if (beanEl != null) {
            BeanDefinitionHolder holder = ctx.getDelegate().parseBeanDefinitionElement(beanEl);

            ctx.registerBeanComponent(new BeanComponentDefinition(holder.getBeanDefinition(), holder.getBeanName()));

            return Optional.of(new RuntimeBeanReference(holder.getBeanName()));
        }
    }

    return Optional.empty();
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:24,代码来源:HekateBeanDefinitionParser.java

示例5: doScan

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
@Override
public Set<BeanDefinitionHolder> doScan(String... basePackages) {
    Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);
    if (beanDefinitions.isEmpty()) {
        logger.warn("No  mapper was found in '" + Arrays.toString(basePackages) + "' package. Please check your configuration.");
    } else {
        for (BeanDefinitionHolder holder : beanDefinitions) {
            GenericBeanDefinition definition = (GenericBeanDefinition) holder.getBeanDefinition();
            if (logger.isDebugEnabled()) {
                logger.debug("Creating MapperFactoryBean with name '" + holder.getBeanName() + "' and '" + definition.getBeanClassName()
                        + "' mapperInterface");
            }
            definition.getPropertyValues().add("mapperProxy", getRegistry().getBeanDefinition("mapperProxy"));
            definition.getPropertyValues().add("mapperInterface", definition.getBeanClassName());
            definition.setBeanClass(MapperFactoryBean.class);
            definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
        }
    }
    return beanDefinitions;
}
 
开发者ID:lftao,项目名称:jkami,代码行数:21,代码来源:ClassPathMapperScanner.java

示例6: register

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
public static BeanDefinitionHolder register(Element ele, BeanDefinitionHolder bdHolder, ParserContext parserContext) {
	if (bdHolder != null) {
		String name = bdHolder.getBeanName();
		checkReservedName(name, ele, parserContext);
		checkUniqueName(name, parserContext.getRegistry());
		try {
			// add non-lenient constructor resolution
			BeanDefinition beanDefinition = bdHolder.getBeanDefinition();
			if (beanDefinition instanceof AbstractBeanDefinition) {
				AbstractBeanDefinition abd = (AbstractBeanDefinition) beanDefinition;
				abd.setLenientConstructorResolution(false);
				abd.setNonPublicAccessAllowed(false);
			}

			// Register the final decorated instance.
			BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, parserContext.getRegistry());
		} catch (BeanDefinitionStoreException ex) {
			parserContext.getReaderContext().error(
					"Failed to register bean definition with name '" + bdHolder.getBeanName() + "'", ele, ex);
		}
		// register component (and send registration events)
		parserContext.registerComponent(new BeanComponentDefinition(bdHolder));
	}
	return bdHolder;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:26,代码来源:ParsingUtils.java

示例7: decorateIfRequired

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
public static BeanDefinitionHolder decorateIfRequired(Node node, BeanDefinitionHolder originalDef,
		ParserContext parserContext) {

	String namespaceUri = node.getNamespaceURI();
	if (!parserContext.getDelegate().isDefaultNamespace(namespaceUri) && !isRFC124Namespace(namespaceUri)) {
		NamespaceHandler handler =
				parserContext.getReaderContext().getNamespaceHandlerResolver().resolve(namespaceUri);
		if (handler != null) {
			return handler.decorate(node, originalDef, new ParserContext(parserContext.getReaderContext(),
					parserContext.getDelegate()));
		} else if (namespaceUri.startsWith("http://www.springframework.org/")) {
			parserContext.getReaderContext().error(
					"Unable to locate Spring NamespaceHandler for XML schema namespace [" + namespaceUri + "]",
					node);
		} else {
			// A custom namespace, not to be handled by Spring - maybe "xml:...".
		}
	}
	return originalDef;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:21,代码来源:ParsingUtils.java

示例8: parse

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	// Obtain bean definitions for all relevant BeanPostProcessors.
	Set<BeanDefinitionHolder> processorDefinitions =
			AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);

	// Register component for the surrounding <context:annotation-config> element.
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	parserContext.pushContainingComponent(compDefinition);

	// Nest the concrete beans in the surrounding component.
	for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
		parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
	}

	// Finally register the composite component.
	parserContext.popAndRegisterContainingComponent();

	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:AnnotationConfigBeanDefinitionParser.java

示例9: parse

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
public void parse(Set<BeanDefinitionHolder> configCandidates) {
	for (BeanDefinitionHolder holder : configCandidates) {
		BeanDefinition bd = holder.getBeanDefinition();
		try {
			if (bd instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) bd).hasBeanClass()) {
				parse(((AbstractBeanDefinition) bd).getBeanClass(), holder.getBeanName());
			}
			else {
				parse(bd.getBeanClassName(), holder.getBeanName());
			}
		}
		catch (IOException ex) {
			throw new BeanDefinitionStoreException("Failed to load bean class: " + bd.getBeanClassName(), ex);
		}
	}
	processDeferredImportSelectors();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:ConfigurationClassParser.java

示例10: registerComponents

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
protected void registerComponents(
		XmlReaderContext readerContext, Set<BeanDefinitionHolder> beanDefinitions, Element element) {

	Object source = readerContext.extractSource(element);
	CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);

	for (BeanDefinitionHolder beanDefHolder : beanDefinitions) {
		compositeDef.addNestedComponent(new BeanComponentDefinition(beanDefHolder));
	}

	// Register annotation config processors, if necessary.
	boolean annotationConfig = true;
	if (element.hasAttribute(ANNOTATION_CONFIG_ATTRIBUTE)) {
		annotationConfig = Boolean.valueOf(element.getAttribute(ANNOTATION_CONFIG_ATTRIBUTE));
	}
	if (annotationConfig) {
		Set<BeanDefinitionHolder> processorDefinitions =
				AnnotationConfigUtils.registerAnnotationConfigProcessors(readerContext.getRegistry(), source);
		for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
			compositeDef.addNestedComponent(new BeanComponentDefinition(processorDefinition));
		}
	}

	readerContext.fireComponentRegistered(compositeDef);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:ComponentScanBeanDefinitionParser.java

示例11: doScan

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
/**
 * Perform a scan within the specified base packages,
 * returning the registered bean definitions.
 * <p>This method does <i>not</i> register an annotation config processor
 * but rather leaves this up to the caller.
 * @param basePackages the packages to check for annotated classes
 * @return set of beans registered if any for tooling registration purposes (never {@code null})
 */
protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
	Assert.notEmpty(basePackages, "At least one base package must be specified");
	Set<BeanDefinitionHolder> beanDefinitions = new LinkedHashSet<BeanDefinitionHolder>();
	for (String basePackage : basePackages) {
		Set<BeanDefinition> candidates = findCandidateComponents(basePackage);
		for (BeanDefinition candidate : candidates) {
			ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(candidate);
			candidate.setScope(scopeMetadata.getScopeName());
			String beanName = this.beanNameGenerator.generateBeanName(candidate, this.registry);
			if (candidate instanceof AbstractBeanDefinition) {
				postProcessBeanDefinition((AbstractBeanDefinition) candidate, beanName);
			}
			if (candidate instanceof AnnotatedBeanDefinition) {
				AnnotationConfigUtils.processCommonDefinitionAnnotations((AnnotatedBeanDefinition) candidate);
			}
			if (checkCandidate(beanName, candidate)) {
				BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(candidate, beanName);
				definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
				beanDefinitions.add(definitionHolder);
				registerBeanDefinition(definitionHolder, this.registry);
			}
		}
	}
	return beanDefinitions;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:ClassPathBeanDefinitionScanner.java

示例12: isAutowireCandidate

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的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

示例13: registerBeanDefinition

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
/**
 * Register the given bean definition with the given bean factory.
 * @param definitionHolder the bean definition including name and aliases
 * @param registry the bean factory to register with
 * @throws BeanDefinitionStoreException if registration failed
 */
public static void registerBeanDefinition(
		BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry)
		throws BeanDefinitionStoreException {

	// Register bean definition under primary name.
	String beanName = definitionHolder.getBeanName();
	registry.registerBeanDefinition(beanName, definitionHolder.getBeanDefinition());

	// Register aliases for bean name, if any.
	String[] aliases = definitionHolder.getAliases();
	if (aliases != null) {
		for (String aliase : aliases) {
			registry.registerAlias(beanName, aliase);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:BeanDefinitionReaderUtils.java

示例14: isAutowireCandidate

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

示例15: processBeanDefinition

import org.springframework.beans.factory.config.BeanDefinitionHolder; //导入依赖的package包/类
/**
 * Process the given bean element, parsing the bean definition
 * and registering it with the registry.
 */
protected void processBeanDefinition(Element ele, BeanDefinitionParserDelegate delegate) {
	BeanDefinitionHolder bdHolder = delegate.parseBeanDefinitionElement(ele);
	if (bdHolder != null) {
		bdHolder = delegate.decorateBeanDefinitionIfRequired(ele, bdHolder);
		try {
			// Register the final decorated instance.
			BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, getReaderContext().getRegistry());
		}
		catch (BeanDefinitionStoreException ex) {
			getReaderContext().error("Failed to register bean definition with name '" +
					bdHolder.getBeanName() + "'", ele, ex);
		}
		// Send registration event.
		getReaderContext().fireComponentRegistered(new BeanComponentDefinition(bdHolder));
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:DefaultBeanDefinitionDocumentReader.java


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