Search in sources :

Example 31 with BeanDefinitionRegistry

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

the class Foo method setUp.

@BeforeEach
public void setUp() {
    beanFactory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory).loadBeanDefinitions(new ClassPathResource("FactoryBeanLookupTests-context.xml", this.getClass()));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) ClassPathResource(org.springframework.core.io.ClassPathResource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 32 with BeanDefinitionRegistry

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

the class AnnotationBeanNameGeneratorTests method generateBeanNameWithNamedComponentWhereTheNameIsBlank.

@Test
public void generateBeanNameWithNamedComponentWhereTheNameIsBlank() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentWithBlankName.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertThat(beanName).as("The generated beanName must *never* be null.").isNotNull();
    assertThat(StringUtils.hasText(beanName)).as("The generated beanName must *never* be blank.").isTrue();
    String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
    assertThat(beanName).isEqualTo(expectedGeneratedBeanName);
}
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 33 with BeanDefinitionRegistry

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

the class AnnotationBeanNameGeneratorTests method generateBeanNameFromComposedControllerAnnotationWithStringValue.

@Test
public void generateBeanNameFromComposedControllerAnnotationWithStringValue() {
    // SPR-11360
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithStringValue.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertThat(beanName).isEqualTo("restController");
}
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 34 with BeanDefinitionRegistry

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

the class AnnotationConfigWebApplicationContextTests method withBeanNameGenerator.

@Test
@SuppressWarnings("resource")
public void withBeanNameGenerator() {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {

        @Override
        public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
            return "custom-" + super.generateBeanName(definition, registry);
        }
    });
    ctx.setConfigLocation(Config.class.getName());
    ctx.refresh();
    assertThat(ctx.containsBean("custom-myConfig")).isTrue();
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) AnnotationBeanNameGenerator(org.springframework.context.annotation.AnnotationBeanNameGenerator) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.jupiter.api.Test)

Example 35 with BeanDefinitionRegistry

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

the class AnnotationDrivenJmsBeanDefinitionParser method parse.

@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
    Object source = parserContext.extractSource(element);
    // Register component for the surrounding <jms:annotation-driven> element.
    CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
    parserContext.pushContainingComponent(compDefinition);
    // Nest the concrete post-processor bean in the surrounding component.
    BeanDefinitionRegistry registry = parserContext.getRegistry();
    if (registry.containsBeanDefinition(JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)) {
        parserContext.getReaderContext().error("Only one JmsListenerAnnotationBeanPostProcessor may exist within the context.", source);
    } else {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition("org.springframework.jms.annotation.JmsListenerAnnotationBeanPostProcessor");
        builder.getRawBeanDefinition().setSource(source);
        String endpointRegistry = element.getAttribute("registry");
        if (StringUtils.hasText(endpointRegistry)) {
            builder.addPropertyReference("endpointRegistry", endpointRegistry);
        } else {
            registerDefaultEndpointRegistry(source, parserContext);
        }
        String containerFactory = element.getAttribute("container-factory");
        if (StringUtils.hasText(containerFactory)) {
            builder.addPropertyValue("containerFactoryBeanName", containerFactory);
        }
        String handlerMethodFactory = element.getAttribute("handler-method-factory");
        if (StringUtils.hasText(handlerMethodFactory)) {
            builder.addPropertyReference("messageHandlerMethodFactory", handlerMethodFactory);
        }
        registerInfrastructureBean(parserContext, builder, JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME);
    }
    // Finally register the composite component.
    parserContext.popAndRegisterContainingComponent();
    return null;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) Nullable(org.springframework.lang.Nullable)

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