Search in sources :

Example 16 with BeanDefinitionRegistry

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

the class ConverterParser method parseInternal.

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionRegistry registry = parserContext.getRegistry();
    BeanComponentDefinition converterDefinition = IntegrationNamespaceUtils.parseInnerHandlerDefinition(element, parserContext);
    if (converterDefinition != null) {
        INTEGRATION_CONVERTER_INITIALIZER.registerConverter(registry, converterDefinition);
    } else {
        String beanName = element.getAttribute("ref");
        Assert.isTrue(StringUtils.hasText(beanName), "Either a 'ref' attribute pointing to a Converter or a <bean> sub-element defining a Converter is required.");
        INTEGRATION_CONVERTER_INITIALIZER.registerConverter(registry, new RuntimeBeanReference(beanName));
    }
    return null;
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 17 with BeanDefinitionRegistry

use of org.springframework.beans.factory.support.BeanDefinitionRegistry 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 18 with BeanDefinitionRegistry

use of org.springframework.beans.factory.support.BeanDefinitionRegistry 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)

Example 19 with BeanDefinitionRegistry

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

the class DslIntegrationConfigurationInitializer method initialize.

@Override
public void initialize(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
    Assert.isInstanceOf(BeanDefinitionRegistry.class, configurableListableBeanFactory, "To use Spring Integration Java DSL the 'beanFactory' has to be an instance of " + "'BeanDefinitionRegistry'. Consider using 'GenericApplicationContext' implementation.");
    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) configurableListableBeanFactory;
    if (!registry.containsBeanDefinition(INTEGRATION_FLOW_BPP_BEAN_NAME)) {
        registry.registerBeanDefinition(INTEGRATION_FLOW_BPP_BEAN_NAME, new RootBeanDefinition(IntegrationFlowBeanPostProcessor.class));
        registry.registerBeanDefinition(INTEGRATION_FLOW_CONTEXT_BEAN_NAME, new RootBeanDefinition(StandardIntegrationFlowContext.class));
    }
}
Also used : IntegrationFlowBeanPostProcessor(org.springframework.integration.dsl.IntegrationFlowBeanPostProcessor) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition)

Example 20 with BeanDefinitionRegistry

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

the class IntegrationFlowBeanPostProcessor method registerComponent.

@SuppressWarnings("unchecked")
private void registerComponent(Object component, String beanName, String parentName, BeanDefinitionCustomizer... customizers) {
    BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition((Class<Object>) component.getClass(), () -> component).applyCustomizers(customizers).getRawBeanDefinition();
    ((BeanDefinitionRegistry) this.beanFactory).registerBeanDefinition(beanName, beanDefinition);
    if (parentName != null) {
        this.beanFactory.registerDependentBean(parentName, beanName);
    }
    this.beanFactory.getBean(beanName);
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Aggregations

BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)72 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)29 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)17 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)13 Test (org.junit.jupiter.api.Test)12 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)12 SimpleBeanDefinitionRegistry (org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry)11 Map (java.util.Map)9 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)9 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)6 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)5 Test (org.junit.Test)4 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)4 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)4 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)4 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)4 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)4 ApplicationContext (org.springframework.context.ApplicationContext)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 HashMap (java.util.HashMap)3