Search in sources :

Example 81 with BeanDefinitionRegistry

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

the class AnnotationBeanNameGeneratorTests method generateBeanNameFromMetaComponentWithStringValue.

@Test
public void generateBeanNameFromMetaComponentWithStringValue() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromStringMeta.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertThat(beanName).isEqualTo("henry");
}
Also used : SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 82 with BeanDefinitionRegistry

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

the class AbstractInterceptorDrivenBeanDefinitionDecorator method decorate.

@Override
public final BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definitionHolder, ParserContext parserContext) {
    BeanDefinitionRegistry registry = parserContext.getRegistry();
    // get the root bean name - will be the name of the generated proxy factory bean
    String existingBeanName = definitionHolder.getBeanName();
    BeanDefinition targetDefinition = definitionHolder.getBeanDefinition();
    BeanDefinitionHolder targetHolder = new BeanDefinitionHolder(targetDefinition, existingBeanName + ".TARGET");
    // delegate to subclass for interceptor definition
    BeanDefinition interceptorDefinition = createInterceptorDefinition(node);
    // generate name and register the interceptor
    String interceptorName = existingBeanName + '.' + getInterceptorNameSuffix(interceptorDefinition);
    BeanDefinitionReaderUtils.registerBeanDefinition(new BeanDefinitionHolder(interceptorDefinition, interceptorName), registry);
    BeanDefinitionHolder result = definitionHolder;
    if (!isProxyFactoryBeanDefinition(targetDefinition)) {
        // create the proxy definition
        RootBeanDefinition proxyDefinition = new RootBeanDefinition();
        // create proxy factory bean definition
        proxyDefinition.setBeanClass(ProxyFactoryBean.class);
        proxyDefinition.setScope(targetDefinition.getScope());
        proxyDefinition.setLazyInit(targetDefinition.isLazyInit());
        // set the target
        proxyDefinition.setDecoratedDefinition(targetHolder);
        proxyDefinition.getPropertyValues().add("target", targetHolder);
        // create the interceptor names list
        proxyDefinition.getPropertyValues().add("interceptorNames", new ManagedList<String>());
        // copy autowire settings from original bean definition.
        proxyDefinition.setAutowireCandidate(targetDefinition.isAutowireCandidate());
        proxyDefinition.setPrimary(targetDefinition.isPrimary());
        if (targetDefinition instanceof AbstractBeanDefinition) {
            proxyDefinition.copyQualifiersFrom((AbstractBeanDefinition) targetDefinition);
        }
        // wrap it in a BeanDefinitionHolder with bean name
        result = new BeanDefinitionHolder(proxyDefinition, existingBeanName);
    }
    addInterceptorNameToList(interceptorName, result.getBeanDefinition());
    return result;
}
Also used : AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 83 with BeanDefinitionRegistry

use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project qi4j-sdk by Qi4j.

the class Qi4jServiceBeanDefinitionParser method parse.

@Override
public final BeanDefinition parse(Element anElement, ParserContext aParserContext) {
    String serviceId = anElement.getAttribute(SERVICE_ID);
    // Service factory bean
    BeanDefinitionBuilder builder = rootBeanDefinition(ServiceFactoryBean.class);
    builder.addConstructorArgReference(BEAN_ID_QI4J_APPLICATION);
    builder.addConstructorArgValue(serviceId);
    AbstractBeanDefinition definition = builder.getBeanDefinition();
    // Register service factory bean
    BeanDefinitionRegistry definitionRegistry = aParserContext.getRegistry();
    definitionRegistry.registerBeanDefinition(serviceId, definition);
    return definition;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)

Example 84 with BeanDefinitionRegistry

use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project qi4j-sdk by Qi4j.

the class Qi4jBootstrapBeanDefinitionParser method registerBean.

private void registerBean(ParserContext aParserContext, BeanDefinition aBeanDefinition) {
    BeanDefinitionRegistry registry = aParserContext.getRegistry();
    registry.registerBeanDefinition(BEAN_ID_QI4J_APPLICATION, aBeanDefinition);
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)

Example 85 with BeanDefinitionRegistry

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

the class ClosureClassIgnoringComponentScanBeanDefinitionParser method createScanner.

@Override
protected ClassPathBeanDefinitionScanner createScanner(XmlReaderContext readerContext, boolean useDefaultFilters) {
    final ClassPathBeanDefinitionScanner scanner = super.createScanner(readerContext, useDefaultFilters);
    BeanDefinitionRegistry beanDefinitionRegistry = readerContext.getRegistry();
    GrailsPluginManager pluginManager = null;
    if (beanDefinitionRegistry instanceof HierarchicalBeanFactory) {
        HierarchicalBeanFactory beanFactory = (HierarchicalBeanFactory) beanDefinitionRegistry;
        BeanFactory parent = beanFactory.getParentBeanFactory();
        if (parent != null && parent.containsBean(GrailsPluginManager.BEAN_NAME)) {
            pluginManager = parent.getBean(GrailsPluginManager.BEAN_NAME, GrailsPluginManager.class);
        }
    }
    if (pluginManager != null) {
        List<TypeFilter> typeFilters = pluginManager.getTypeFilters();
        for (TypeFilter typeFilter : typeFilters) {
            scanner.addIncludeFilter(typeFilter);
        }
    }
    return scanner;
}
Also used : ClassPathBeanDefinitionScanner(org.springframework.context.annotation.ClassPathBeanDefinitionScanner) GrailsPluginManager(grails.plugins.GrailsPluginManager) HierarchicalBeanFactory(org.springframework.beans.factory.HierarchicalBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) TypeFilter(org.springframework.core.type.filter.TypeFilter) HierarchicalBeanFactory(org.springframework.beans.factory.HierarchicalBeanFactory)

Aggregations

BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)86 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)36 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)20 Test (org.junit.jupiter.api.Test)15 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)13 SimpleBeanDefinitionRegistry (org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry)13 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)12 ApplicationContext (org.springframework.context.ApplicationContext)10 Map (java.util.Map)9 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)8 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)7 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)7 Test (org.junit.Test)5 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)5 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)5 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)5 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)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