Search in sources :

Example 36 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project loc-framework by lord-of-code.

the class LocElasticJobAutoConfiguration method createSpringJobScheduler.

private void createSpringJobScheduler(String name, List<Object> argList) {
    ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext;
    BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) configurableApplicationContext.getBeanFactory();
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(SpringJobScheduler.class);
    builder.setInitMethodName("init");
    for (Object arg : argList) {
        builder.addConstructorArgValue(arg);
    }
    beanDefinitionRegistry.registerBeanDefinition(name, builder.getBeanDefinition());
    log.info("spring bean name {} register success ", name);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)

Example 37 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.

the class IntegrationRegistrar method registerMessageBuilderFactory.

private void registerMessageBuilderFactory(BeanDefinitionRegistry registry) {
    boolean alreadyRegistered = false;
    if (registry instanceof ListableBeanFactory) {
        alreadyRegistered = ((ListableBeanFactory) registry).containsBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
    } else {
        alreadyRegistered = registry.isBeanNameInUse(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
    }
    if (!alreadyRegistered) {
        BeanDefinitionBuilder mbfBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultMessageBuilderFactory.class).addPropertyValue("readOnlyHeaders", IntegrationProperties.getExpressionFor(IntegrationProperties.READ_ONLY_HEADERS));
        registry.registerBeanDefinition(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME, mbfBuilder.getBeanDefinition());
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) DefaultMessageBuilderFactory(org.springframework.integration.support.DefaultMessageBuilderFactory) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Example 38 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.

the class IntegrationRegistrar method registerIntegrationProperties.

/**
 * Register {@code integrationGlobalProperties} bean if necessary.
 * @param registry The {@link BeanDefinitionRegistry} to register additional {@link BeanDefinition}s.
 */
private void registerIntegrationProperties(BeanDefinitionRegistry registry) {
    boolean alreadyRegistered = false;
    if (registry instanceof ListableBeanFactory) {
        alreadyRegistered = ((ListableBeanFactory) registry).containsBean(IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME);
    } else {
        alreadyRegistered = registry.isBeanNameInUse(IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME);
    }
    if (!alreadyRegistered) {
        ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(this.classLoader);
        try {
            Resource[] defaultResources = resourceResolver.getResources("classpath*:META-INF/spring.integration.default.properties");
            Resource[] userResources = resourceResolver.getResources("classpath*:META-INF/spring.integration.properties");
            List<Resource> resources = new LinkedList<Resource>(Arrays.asList(defaultResources));
            resources.addAll(Arrays.asList(userResources));
            BeanDefinitionBuilder integrationPropertiesBuilder = BeanDefinitionBuilder.genericBeanDefinition(PropertiesFactoryBean.class).addPropertyValue("locations", resources);
            registry.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME, integrationPropertiesBuilder.getBeanDefinition());
        } catch (IOException e) {
            logger.warn("Cannot load 'spring.integration.properties' Resources.", e);
        }
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) LinkedList(java.util.LinkedList)

Example 39 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.

the class IntegrationRegistrar method registerIntegrationEvaluationContext.

/**
 * Register {@link IntegrationEvaluationContextFactoryBean} bean, if necessary.
 * @param registry The {@link BeanDefinitionRegistry} to register additional {@link BeanDefinition}s.
 */
private void registerIntegrationEvaluationContext(BeanDefinitionRegistry registry) {
    if (!registry.containsBeanDefinition(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME)) {
        BeanDefinitionBuilder integrationEvaluationContextBuilder = BeanDefinitionBuilder.genericBeanDefinition(IntegrationEvaluationContextFactoryBean.class);
        integrationEvaluationContextBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        BeanDefinitionHolder integrationEvaluationContextHolder = new BeanDefinitionHolder(integrationEvaluationContextBuilder.getBeanDefinition(), IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME);
        BeanDefinitionReaderUtils.registerBeanDefinition(integrationEvaluationContextHolder, registry);
    }
    if (!registry.containsBeanDefinition(IntegrationContextUtils.INTEGRATION_SIMPLE_EVALUATION_CONTEXT_BEAN_NAME)) {
        BeanDefinitionBuilder integrationEvaluationContextBuilder = BeanDefinitionBuilder.genericBeanDefinition(IntegrationSimpleEvaluationContextFactoryBean.class);
        integrationEvaluationContextBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        BeanDefinitionHolder integrationEvaluationContextHolder = new BeanDefinitionHolder(integrationEvaluationContextBuilder.getBeanDefinition(), IntegrationContextUtils.INTEGRATION_SIMPLE_EVALUATION_CONTEXT_BEAN_NAME);
        BeanDefinitionReaderUtils.registerBeanDefinition(integrationEvaluationContextHolder, registry);
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder)

Example 40 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.

the class IntegrationRegistrar method registerDefaultDatatypeChannelMessageConverter.

/**
 * Register the default datatype channel MessageConverter.
 * @param registry the registry.
 */
private void registerDefaultDatatypeChannelMessageConverter(BeanDefinitionRegistry registry) {
    boolean alreadyRegistered = false;
    if (registry instanceof ListableBeanFactory) {
        alreadyRegistered = ((ListableBeanFactory) registry).containsBean(IntegrationContextUtils.INTEGRATION_DATATYPE_CHANNEL_MESSAGE_CONVERTER_BEAN_NAME);
    } else {
        alreadyRegistered = registry.isBeanNameInUse(IntegrationContextUtils.INTEGRATION_DATATYPE_CHANNEL_MESSAGE_CONVERTER_BEAN_NAME);
    }
    if (!alreadyRegistered) {
        BeanDefinitionBuilder converterBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultDatatypeChannelMessageConverter.class);
        registry.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_DATATYPE_CHANNEL_MESSAGE_CONVERTER_BEAN_NAME, converterBuilder.getBeanDefinition());
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Aggregations

BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)539 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)115 Element (org.w3c.dom.Element)99 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)60 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)60 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)59 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)53 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)47 ManagedList (org.springframework.beans.factory.support.ManagedList)33 ManagedMap (org.springframework.beans.factory.support.ManagedMap)29 HashMap (java.util.HashMap)19 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)19 Test (org.junit.jupiter.api.Test)16 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)16 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)12 Node (org.w3c.dom.Node)12 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)10 TypedStringValue (org.springframework.beans.factory.config.TypedStringValue)10 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)10