當前位置: 首頁>>代碼示例>>Java>>正文


Java BeanDefinitionReaderUtils類代碼示例

本文整理匯總了Java中org.springframework.beans.factory.support.BeanDefinitionReaderUtils的典型用法代碼示例。如果您正苦於以下問題:Java BeanDefinitionReaderUtils類的具體用法?Java BeanDefinitionReaderUtils怎麽用?Java BeanDefinitionReaderUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BeanDefinitionReaderUtils類屬於org.springframework.beans.factory.support包,在下文中一共展示了BeanDefinitionReaderUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: registerBeanDefinitions

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    Set<String> basePackages = getBasePackages(importingClassMetadata);
    ClassPathScanningCandidateComponentProvider scanner = getScanner();
    scanner.addIncludeFilter(new AnnotationTypeFilter(MuonRepository.class));
    for (String basePackage : basePackages) {
        Set<BeanDefinition> candidateComponents = scanner
                .findCandidateComponents(basePackage);
        for (BeanDefinition candidateComponent : candidateComponents) {
            if (candidateComponent instanceof AnnotatedBeanDefinition) {

                AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent;
                AnnotationMetadata annotationMetadata = beanDefinition.getMetadata();
                Assert.isTrue(annotationMetadata.isInterface(),
                        "@FeignClient can only be specified on an interface");

                BeanDefinitionHolder holder = createBeanDefinition(annotationMetadata);
                BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
            }
        }
    }

}
 
開發者ID:muoncore,項目名稱:muon-java,代碼行數:24,代碼來源:MuonRepositoryRegistrar.java

示例2: generateBeanName

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
protected String generateBeanName(String prefix, BeanDefinition def, ParserContext parserContext) {
	BeanDefinitionRegistry registry = parserContext.getRegistry();
	String name = prefix + BeanDefinitionReaderUtils.generateBeanName(def, registry);
	String generated = name;
	int counter = 0;

	while (registry.containsBeanDefinition(generated)) {
		generated = name + BeanFactoryUtils.GENERATED_BEAN_NAME_SEPARATOR + counter;
		if (parserContext.isNested()) {
			generated = generated.concat("#generated");
		}
		counter++;
	}

	return generated;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:17,代碼來源:AbstractReferenceDefinitionParser.java

示例3: register

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的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

示例4: generateBlueprintBeanName

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
/**
 * Generates a Blueprint specific bean name.
 * 
 * @param definition
 * @param registry
 * @param isInnerBean
 * @return
 * @throws BeanDefinitionStoreException
 */
public static String generateBlueprintBeanName(BeanDefinition definition, BeanDefinitionRegistry registry,
		boolean isInnerBean) throws BeanDefinitionStoreException {

	String initialName =
			BLUEPRINT_GENERATED_NAME_PREFIX
					+ BeanDefinitionReaderUtils.generateBeanName(definition, registry, isInnerBean);

	String generatedName = initialName;
	int counter = 0;
	while (registry.containsBeanDefinition(generatedName)) {
		generatedName = initialName + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + counter;
		counter++;
	}

	return generatedName;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:26,代碼來源:ParsingUtils.java

示例5: processBeanDefinition

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的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

示例6: parse

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
public BeanDefinition parse(Element element, ParserContext parserContext)
{
    BeanDefinitionBuilder dwrController = BeanDefinitionBuilder.rootBeanDefinition(DwrController.class);
    List configurators = new ManagedList();
    configurators.add(new RuntimeBeanReference(DEFAULT_SPRING_CONFIGURATOR_ID));
    dwrController.addPropertyValue("configurators", configurators);

    String debug = element.getAttribute("debug");
    if (StringUtils.hasText(debug))
    {
        dwrController.addPropertyValue("debug", debug);
    }

    String beanName = element.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);
    String nameAttr = element.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE);
    String[] aliases = null;
    if (!StringUtils.hasText(beanName))
    {
        beanName = element.getAttribute("name");
    }
    else
    {
        String aliasName = element.getAttribute("name");
        if (StringUtils.hasText(aliasName))
        {
            aliases = StringUtils.tokenizeToStringArray(nameAttr, BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS);
        }
    }

    parseControllerParameters(dwrController, element);
    
    BeanDefinitionHolder holder = new BeanDefinitionHolder(dwrController.getBeanDefinition(), beanName, aliases);
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());

    return dwrController.getBeanDefinition();
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:37,代碼來源:DwrNamespaceHandler.java

示例7: load

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
private void load(ClassLoader loader, String name) {
    try {
        DefaultListableBeanFactory lbf = (DefaultListableBeanFactory) applicationContext.getAutowireCapableBeanFactory();
        BeanDefinition bd = BeanDefinitionReaderUtils.createBeanDefinition(null, name, loader);
        String dynamicBeanName = generator.uuid();
        lbf.registerBeanDefinition(dynamicBeanName, bd);
        Object bean = lbf.getBean(dynamicBeanName);
        String beanName = getBeanName(bean.getClass());
        Object oldBean = null;
        if (beanName != null) {
            oldBean = container.getBean(beanName);
            container.mapBeanName(beanName, dynamicBeanName);
        }
        inject(bean.getClass(), null, bean);
        inject(bean, oldBean);
    } catch (Exception e) {
        logger.warn(e, "重新載入[{}]時發生異常!", name);
    }
}
 
開發者ID:heisedebaise,項目名稱:tephra,代碼行數:20,代碼來源:ClassReloaderImpl.java

示例8: naming

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
@Test
public void naming() {
	String className = GeneratedNameBean.class.getName();

	String targetName = className + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + "0";
	GeneratedNameBean topLevel1 = (GeneratedNameBean) beanFactory.getBean(targetName);
	assertNotNull(topLevel1);

	targetName = className + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + "1";
	GeneratedNameBean topLevel2 = (GeneratedNameBean) beanFactory.getBean(targetName);
	assertNotNull(topLevel2);

	GeneratedNameBean child1 = topLevel1.getChild();
	assertNotNull(child1.getBeanName());
	assertTrue(child1.getBeanName().startsWith(className));

	GeneratedNameBean child2 = topLevel2.getChild();
	assertNotNull(child2.getBeanName());
	assertTrue(child2.getBeanName().startsWith(className));

	assertFalse(child1.getBeanName().equals(child2.getBeanName()));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:BeanNameGenerationTests.java

示例9: registerSoapClient

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
private void registerSoapClient(BeanDefinitionRegistry registry,
                                AnnotationMetadata annotationMetadata,
                                Map<String, Object> attributes) {
    String className = annotationMetadata.getClassName();
    BeanDefinitionBuilder definition = BeanDefinitionBuilder
            .genericBeanDefinition(SoapClientFactoryBean.class);
    validate(attributes);

    Class<?> serviceType = getClientService(attributes);
    // Type name of annotated interface
    definition.addPropertyValue("type", getClassByName(className));
    // Soap service type
    definition.addPropertyValue("service", serviceType);
    definition.addPropertyValue("soapMethods", getAnnotatedMethods(annotationMetadata));
    definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);

    String alias = className + "SoapClient";
    AbstractBeanDefinition beanDefinition = definition.getBeanDefinition();
    beanDefinition.setPrimary(true);
    BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className,
            new String[] { alias });
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
}
 
開發者ID:Salmondx,項目名稱:spring-soap-client-starter,代碼行數:24,代碼來源:SoapClientRegistrar.java

示例10: registerRetrofitClient

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
private void registerRetrofitClient(BeanDefinitionRegistry registry,
								 AnnotationMetadata annotationMetadata, Map<String, Object> attributes) {
	String className = annotationMetadata.getClassName();
	BeanDefinitionBuilder definition = BeanDefinitionBuilder
			.genericBeanDefinition(RetrofitClientFactoryBean.class);
	validate(attributes);
	definition.addPropertyValue("url", getUrl(attributes));
	String name = getName(attributes);
	definition.addPropertyValue("name", name);
	definition.addPropertyValue("type", className);
	definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);

	String alias = name + "RetrofitClient";
	AbstractBeanDefinition beanDefinition = definition.getBeanDefinition();
	beanDefinition.setPrimary(true);

	String qualifier = getQualifier(attributes);
	if (StringUtils.hasText(qualifier)) {
		alias = qualifier;
	}

	BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className,
			new String[] { alias });
	BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
}
 
開發者ID:spring-cloud-incubator,項目名稱:spring-cloud-square,代碼行數:26,代碼來源:RetrofitClientsRegistrar.java

示例11: testNaming

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
public void testNaming() {
	String className = GeneratedNameBean.class.getName();

	String targetName = className + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + "0";
	GeneratedNameBean topLevel1 = (GeneratedNameBean) beanFactory.getBean(targetName);
	assertNotNull(topLevel1);

	targetName = className + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + "1";
	GeneratedNameBean topLevel2 = (GeneratedNameBean) beanFactory.getBean(targetName);
	assertNotNull(topLevel2);

	GeneratedNameBean child1 = topLevel1.getChild();
	assertNotNull(child1.getBeanName());
	assertTrue(child1.getBeanName().startsWith(className));

	GeneratedNameBean child2 = topLevel2.getChild();
	assertNotNull(child2.getBeanName());
	assertTrue(child2.getBeanName().startsWith(className));

	assertFalse(child1.getBeanName().equals(child2.getBeanName()));
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:22,代碼來源:BeanNameGenerationTests.java

示例12: parse

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
public BeanDefinition parse(Element element, ParserContext parserContext) {
	RootBeanDefinition beanDef = new RootBeanDefinition();
	// never null since the schema requires it 
	String id = element.getAttribute(ID);
	String classname = element.getAttribute(CLASS);
	if (!(StringUtils.hasLength(classname))) {
		System.out.println("Tag 'action' must have a 'class' attribute");
		return null;
	}
	beanDef.setBeanClassName(classname);
	parseRef(element, beanDef);
	// create a bean definition holder to be able to register the
	// bean definition with the bean definition registry
	// (obtained through the ParserContext)
	BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDef, id);
	// register the BeanDefinitionHolder (which contains the bean definition)
	// with the BeanDefinitionRegistry

	BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
	
	return beanDef;
}
 
開發者ID:yaneri,項目名稱:se,代碼行數:23,代碼來源:ActionBeanDefinitionParser.java

示例13: parse

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
public BeanDefinition parse(Element element, ParserContext parserContext) {
	RootBeanDefinition beandef = new RootBeanDefinition();
	// never null since the schema requires it 
	String id = element.getAttribute(ID);
	if(classname == null || classname.isEmpty())
		classname = DEFAULT_CLASS;
	beandef.setBeanClassName(classname);
	
	parseTemplate(element, beandef);
	beandef.setDescription(DomUtils.getChildElementValueByTagName(element, DESCRIPTION));
	parseAction(element, beandef);
	parseFields(element, beandef, parserContext);
	parseChannel(element, beandef);
	BeanDefinitionHolder holder = new BeanDefinitionHolder(beandef, id);
	// register the BeanDefinitionHolder (which contains the bean definition)
	// with the BeanDefinitionRegistry
	BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
	
	return beandef;
}
 
開發者ID:yaneri,項目名稱:se,代碼行數:21,代碼來源:TransactionBeanDefinitionParser.java

示例14: registerAmazonWebserviceClient

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
public static BeanDefinitionHolder registerAmazonWebserviceClient(
        Object source, BeanDefinitionRegistry registry, String serviceNameClassName,
        String customRegionProvider, String customRegion) {

    String beanName = getBeanName(serviceNameClassName);

    if (registry.containsBeanDefinition(beanName)) {
        return new BeanDefinitionHolder(registry.getBeanDefinition(beanName), beanName);
    }

    BeanDefinition definition = getAmazonWebserviceClientBeanDefinition(source, serviceNameClassName, customRegionProvider, customRegion, registry);
    BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, beanName);
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);

    return holder;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:17,代碼來源:AmazonWebserviceClientConfigurationUtils.java

示例15: registerRegionProvider

import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; //導入依賴的package包/類
public static void registerRegionProvider(BeanDefinitionRegistry registry, boolean autoDetect, String configuredRegion) {
    if (autoDetect
            && StringUtils.hasText(configuredRegion)) {
        throw new IllegalArgumentException("No region must be configured if autoDetect is defined as true");
    }

    AbstractBeanDefinition beanDefinition;

    if (autoDetect) {
        beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(Ec2MetadataRegionProvider.class).getBeanDefinition();
    } else if (StringUtils.hasText(configuredRegion)) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(StaticRegionProvider.class);
        builder.addConstructorArgValue(configuredRegion);
        beanDefinition = builder.getBeanDefinition();
    } else {
        throw new IllegalArgumentException("Region must be manually configured or autoDetect enabled");
    }

    BeanDefinitionReaderUtils.registerBeanDefinition(new BeanDefinitionHolder(beanDefinition, REGION_PROVIDER_BEAN_NAME), registry);
    AmazonWebserviceClientConfigurationUtils.replaceDefaultRegionProvider(registry, REGION_PROVIDER_BEAN_NAME);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:22,代碼來源:ContextConfigurationUtils.java


注:本文中的org.springframework.beans.factory.support.BeanDefinitionReaderUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。