Search in sources :

Example 31 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition in project dubbo by alibaba.

the class DubboConfigBindingRegistrar method registerDubboConfigBindingBeanPostProcessor.

private void registerDubboConfigBindingBeanPostProcessor(String beanName, PropertyValues propertyValues, BeanDefinitionRegistry registry) {
    Class<?> processorClass = DubboConfigBindingBeanPostProcessor.class;
    BeanDefinitionBuilder builder = rootBeanDefinition(processorClass);
    builder.addConstructorArgValue(beanName).addConstructorArgValue(propertyValues);
    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.");
    }
}
Also used : DubboConfigBindingBeanPostProcessor(com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition)

Example 32 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition in project elastic-job by dangdangdotcom.

the class AbstractJobBeanDefinitionParser method parseInternal.

@Override
protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
    BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(SpringJobScheduler.class);
    factory.setInitMethodName("init");
    factory.setDestroyMethodName("shutdown");
    if ("".equals(element.getAttribute(CLASS_ATTRIBUTE))) {
        factory.addConstructorArgValue(null);
    } else {
        factory.addConstructorArgValue(BeanDefinitionBuilder.rootBeanDefinition(element.getAttribute(CLASS_ATTRIBUTE)).getBeanDefinition());
    }
    factory.addConstructorArgReference(element.getAttribute(REGISTRY_CENTER_REF_ATTRIBUTE));
    factory.addConstructorArgValue(createLiteJobConfiguration(element));
    BeanDefinition jobEventConfig = createJobEventConfig(element);
    if (null != jobEventConfig) {
        factory.addConstructorArgValue(jobEventConfig);
    }
    factory.addConstructorArgValue(createJobListeners(element));
    return factory.getBeanDefinition();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 33 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition in project grails-core by grails.

the class DefaultBeanConfiguration method createBeanDefinition.

protected AbstractBeanDefinition createBeanDefinition() {
    AbstractBeanDefinition bd = new GenericBeanDefinition();
    if (!constructorArgs.isEmpty()) {
        ConstructorArgumentValues cav = new ConstructorArgumentValues();
        for (Object constructorArg : constructorArgs) {
            cav.addGenericArgumentValue(constructorArg);
        }
        bd.setConstructorArgumentValues(cav);
    }
    if (clazz != null) {
        bd.setLazyInit(clazz.getAnnotation(Lazy.class) != null);
        bd.setBeanClass(clazz);
    }
    bd.setScope(singleton ? AbstractBeanDefinition.SCOPE_SINGLETON : AbstractBeanDefinition.SCOPE_PROTOTYPE);
    if (parentName != null) {
        bd.setParentName(parentName);
    }
    wrapper = new BeanWrapperImpl(bd);
    return bd;
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 34 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition in project spring-framework by spring-projects.

the class ConfigurationClassParser method parse.

public void parse(Set<BeanDefinitionHolder> configCandidates) {
    this.deferredImportSelectors = new LinkedList<>();
    for (BeanDefinitionHolder holder : configCandidates) {
        BeanDefinition bd = holder.getBeanDefinition();
        try {
            if (bd instanceof AnnotatedBeanDefinition) {
                parse(((AnnotatedBeanDefinition) bd).getMetadata(), holder.getBeanName());
            } else if (bd instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) bd).hasBeanClass()) {
                parse(((AbstractBeanDefinition) bd).getBeanClass(), holder.getBeanName());
            } else {
                parse(bd.getBeanClassName(), holder.getBeanName());
            }
        } catch (BeanDefinitionStoreException ex) {
            throw ex;
        } catch (Throwable ex) {
            throw new BeanDefinitionStoreException("Failed to parse configuration class [" + bd.getBeanClassName() + "]", ex);
        }
    }
    processDeferredImportSelectors();
}
Also used : AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 35 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition in project spring-framework by spring-projects.

the class MBeanExportBeanDefinitionParser method parseInternal.

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(AnnotationMBeanExporter.class);
    // Mark as infrastructure bean and attach source location.
    builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
    String defaultDomain = element.getAttribute(DEFAULT_DOMAIN_ATTRIBUTE);
    if (StringUtils.hasText(defaultDomain)) {
        builder.addPropertyValue("defaultDomain", defaultDomain);
    }
    String serverBeanName = element.getAttribute(SERVER_ATTRIBUTE);
    if (StringUtils.hasText(serverBeanName)) {
        builder.addPropertyReference("server", serverBeanName);
    } else {
        AbstractBeanDefinition specialServer = MBeanServerBeanDefinitionParser.findServerForSpecialEnvironment();
        if (specialServer != null) {
            builder.addPropertyValue("server", specialServer);
        }
    }
    String registration = element.getAttribute(REGISTRATION_ATTRIBUTE);
    RegistrationPolicy registrationPolicy = RegistrationPolicy.FAIL_ON_EXISTING;
    if (REGISTRATION_IGNORE_EXISTING.equals(registration)) {
        registrationPolicy = RegistrationPolicy.IGNORE_EXISTING;
    } else if (REGISTRATION_REPLACE_EXISTING.equals(registration)) {
        registrationPolicy = RegistrationPolicy.REPLACE_EXISTING;
    }
    builder.addPropertyValue("registrationPolicy", registrationPolicy);
    return builder.getBeanDefinition();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) RegistrationPolicy(org.springframework.jmx.support.RegistrationPolicy)

Aggregations

AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)54 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)16 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)16 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)14 Test (org.junit.Test)10 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)9 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)6 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)5 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)5 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)4 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)4 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)4 BeanComponentDefinitionBuilder (org.springframework.data.config.BeanComponentDefinitionBuilder)4 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)3 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)3 ArrayList (java.util.ArrayList)2 BeanCreationException (org.springframework.beans.factory.BeanCreationException)2 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)2 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)2 ChildBeanDefinition (org.springframework.beans.factory.support.ChildBeanDefinition)2