Search in sources :

Example 91 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.

the class DefaultConfiguringBeanFactoryPostProcessor method registerTaskScheduler.

/**
 * Register a TaskScheduler in the given BeanDefinitionRegistry.
 */
private void registerTaskScheduler(BeanDefinitionRegistry registry) {
    if (this.logger.isInfoEnabled()) {
        this.logger.info("No bean named '" + IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME + "' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.");
    }
    BeanDefinition scheduler = BeanDefinitionBuilder.genericBeanDefinition(ThreadPoolTaskScheduler.class).addPropertyValue("poolSize", IntegrationProperties.getExpressionFor(IntegrationProperties.TASK_SCHEDULER_POOL_SIZE)).addPropertyValue("threadNamePrefix", "task-scheduler-").addPropertyValue("rejectedExecutionHandler", new CallerRunsPolicy()).addPropertyValue("errorHandler", new RootBeanDefinition(MessagePublishingErrorHandler.class)).getBeanDefinition();
    registry.registerBeanDefinition(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, scheduler);
}
Also used : CallerRunsPolicy(java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)

Example 92 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.

the class DefaultConfiguringBeanFactoryPostProcessor method registerInfrastructureBean.

private void registerInfrastructureBean(BeanDefinitionRegistry registry, String className) {
    String[] definitionNames = registry.getBeanDefinitionNames();
    for (String definitionName : definitionNames) {
        BeanDefinition definition = registry.getBeanDefinition(definitionName);
        if (className.equals(definition.getBeanClassName())) {
            if (this.logger.isInfoEnabled()) {
                this.logger.info(className + " is already registered and will be used");
            }
            return;
        }
    }
    RootBeanDefinition beanDefinition = new RootBeanDefinition(className);
    beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    BeanDefinitionReaderUtils.registerWithGeneratedName(beanDefinition, registry);
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 93 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.

the class DefaultConfiguringBeanFactoryPostProcessor method registerNullChannel.

/**
 * Register a null channel in the given BeanDefinitionRegistry. The bean name is defined by the constant
 * {@link IntegrationContextUtils#NULL_CHANNEL_BEAN_NAME}.
 */
private void registerNullChannel(BeanDefinitionRegistry registry) {
    if (registry.containsBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) {
        BeanDefinition nullChannelDefinition = registry.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
        if (NullChannel.class.getName().equals(nullChannelDefinition.getBeanClassName())) {
            return;
        } else {
            throw new IllegalStateException("The bean name '" + IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME + "' is reserved.");
        }
    } else {
        RootBeanDefinition nullChannelDef = new RootBeanDefinition();
        nullChannelDef.setBeanClassName(IntegrationConfigUtils.BASE_PACKAGE + ".channel.NullChannel");
        BeanDefinitionHolder nullChannelHolder = new BeanDefinitionHolder(nullChannelDef, IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
        BeanDefinitionReaderUtils.registerBeanDefinition(nullChannelHolder, registry);
    }
}
Also used : BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) NullChannel(org.springframework.integration.channel.NullChannel)

Example 94 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.

the class FixedSubscriberChannelBeanFactoryPostProcessor method postProcessBeanFactory.

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (beanFactory instanceof BeanDefinitionRegistry) {
        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
        if (this.candidateFixedChannelHandlerMap.size() > 0) {
            for (Entry<String, String> entry : this.candidateFixedChannelHandlerMap.entrySet()) {
                String handlerName = entry.getKey();
                String channelName = entry.getValue();
                BeanDefinition handlerBeanDefinition = null;
                if (registry.containsBeanDefinition(handlerName)) {
                    handlerBeanDefinition = registry.getBeanDefinition(handlerName);
                }
                if (handlerBeanDefinition != null && registry.containsBeanDefinition(channelName)) {
                    BeanDefinition inputChannelDefinition = registry.getBeanDefinition(channelName);
                    if (FixedSubscriberChannel.class.getName().equals(inputChannelDefinition.getBeanClassName())) {
                        ConstructorArgumentValues constructorArgumentValues = inputChannelDefinition.getConstructorArgumentValues();
                        Assert.isTrue(constructorArgumentValues.isEmpty(), "Only one subscriber is allowed for a FixedSubscriberChannel.");
                        constructorArgumentValues.addGenericArgumentValue(handlerBeanDefinition);
                    }
                }
            }
        }
    }
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) FixedSubscriberChannel(org.springframework.integration.channel.FixedSubscriberChannel) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 95 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.

the class IntegrationConverterInitializer method initialize.

@Override
public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
    for (String beanName : registry.getBeanDefinitionNames()) {
        BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);
        if (beanDefinition instanceof AnnotatedBeanDefinition) {
            AnnotationMetadata metadata = ((AnnotatedBeanDefinition) beanDefinition).getMetadata();
            boolean hasIntegrationConverter = metadata.hasAnnotation(IntegrationConverter.class.getName());
            if (!hasIntegrationConverter && beanDefinition.getSource() instanceof MethodMetadata) {
                MethodMetadata beanMethod = (MethodMetadata) beanDefinition.getSource();
                hasIntegrationConverter = beanMethod.isAnnotated(IntegrationConverter.class.getName());
            }
            if (hasIntegrationConverter) {
                this.registerConverter(registry, new RuntimeBeanReference(beanName));
            }
        }
    }
}
Also used : AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) MethodMetadata(org.springframework.core.type.MethodMetadata) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) AnnotationMetadata(org.springframework.core.type.AnnotationMetadata)

Aggregations

BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)601 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)188 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)116 Test (org.junit.jupiter.api.Test)112 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)89 Element (org.w3c.dom.Element)72 Test (org.junit.Test)66 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)60 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)53 ClassPathScanningCandidateComponentProvider (org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider)41 ManagedList (org.springframework.beans.factory.support.ManagedList)39 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)36 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)35 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)34 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)34 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)31 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)30 Method (java.lang.reflect.Method)28 ArrayList (java.util.ArrayList)28 Map (java.util.Map)27