org.springframework.beans.factory.support.AbstractBeanDefinition#setRole ( )源码实例Demo

下面列出了org.springframework.beans.factory.support.AbstractBeanDefinition#setRole ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lams   文件: AnnotationConfigUtils.java
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) {
	if (metadata.isAnnotated(Lazy.class.getName())) {
		abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value"));
	}
	else if (abd.getMetadata() != metadata && abd.getMetadata().isAnnotated(Lazy.class.getName())) {
		abd.setLazyInit(attributesFor(abd.getMetadata(), Lazy.class).getBoolean("value"));
	}

	if (metadata.isAnnotated(Primary.class.getName())) {
		abd.setPrimary(true);
	}
	if (metadata.isAnnotated(DependsOn.class.getName())) {
		abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value"));
	}

	if (abd instanceof AbstractBeanDefinition) {
		AbstractBeanDefinition absBd = (AbstractBeanDefinition) abd;
		if (metadata.isAnnotated(Role.class.getName())) {
			absBd.setRole(attributesFor(metadata, Role.class).getNumber("value").intValue());
		}
		if (metadata.isAnnotated(Description.class.getName())) {
			absBd.setDescription(attributesFor(metadata, Description.class).getString("value"));
		}
	}
}
 
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) {
	if (metadata.isAnnotated(Lazy.class.getName())) {
		abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value"));
	}
	else if (abd.getMetadata() != metadata && abd.getMetadata().isAnnotated(Lazy.class.getName())) {
		abd.setLazyInit(attributesFor(abd.getMetadata(), Lazy.class).getBoolean("value"));
	}

	if (metadata.isAnnotated(Primary.class.getName())) {
		abd.setPrimary(true);
	}
	if (metadata.isAnnotated(DependsOn.class.getName())) {
		abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value"));
	}

	if (abd instanceof AbstractBeanDefinition) {
		AbstractBeanDefinition absBd = (AbstractBeanDefinition) abd;
		if (metadata.isAnnotated(Role.class.getName())) {
			absBd.setRole(attributesFor(metadata, Role.class).getNumber("value").intValue());
		}
		if (metadata.isAnnotated(Description.class.getName())) {
			absBd.setDescription(attributesFor(metadata, Description.class).getString("value"));
		}
	}
}
 
private void registerInfrastructureBeanWithId(AbstractBeanDefinition def, String id,
		ParserContext context, Element element) {

	def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	def.setSource(context.extractSource(element));
	context.registerBeanComponent(new BeanComponentDefinition(def, id));
}
 
private void registerProcessScope(Element element, ParserContext parserContext) {
	Class clz = ProcessScope.class;
	BeanDefinitionBuilder processScopeBDBuilder = BeanDefinitionBuilder.genericBeanDefinition(clz);
	AbstractBeanDefinition scopeBeanDefinition = processScopeBDBuilder.getBeanDefinition();
	scopeBeanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	configureProcessEngine(scopeBeanDefinition, element);
	String beanName = baseBeanName(clz);
	parserContext.getRegistry().registerBeanDefinition(beanName, scopeBeanDefinition);
}
 
private void registerProcessStartAnnotationBeanPostProcessor(Element element, ParserContext parserContext) {
	Class clz = ProcessStartAnnotationBeanPostProcessor.class;

	BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(clz);
	AbstractBeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition();
	beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	configureProcessEngine(beanDefinition, element);

	String beanName = baseBeanName(clz);
	parserContext.getRegistry().registerBeanDefinition(beanName, beanDefinition);
}
 
源代码6 项目: dubbo-2.6.5   文件: DubboConfigBindingRegistrar.java
private void registerDubboConfigBindingBeanPostProcessor(String prefix, String beanName, boolean multiple,
                                                             BeanDefinitionRegistry registry) {

//        对dubbo配置bean实例化过程进行干预
        Class<?> processorClass = DubboConfigBindingBeanPostProcessor.class;

        BeanDefinitionBuilder builder = rootBeanDefinition(processorClass);

        String actualPrefix = multiple ? normalizePrefix(prefix) + beanName : prefix;

        builder.addConstructorArgValue(actualPrefix).addConstructorArgValue(beanName);

        AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();

        beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

        registerWithGeneratedName(beanDefinition, registry);

        if (log.isInfoEnabled()) {
            log.info("The BeanPostProcessor bean definition [" + processorClass.getName()
                    + "] for dubbo config bean [name : " + beanName + "] has been registered.");
        }

    }