Search in sources :

Example 61 with BeanDefinitionRegistry

use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project dubbo by alibaba.

the class DubboConfigBeanDefinitionConflictApplicationListener method onApplicationEvent.

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    ApplicationContext applicationContext = event.getApplicationContext();
    BeanDefinitionRegistry registry = getBeanDefinitionRegistry(applicationContext);
    resolveUniqueApplicationConfigBean(registry, applicationContext);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)

Example 62 with BeanDefinitionRegistry

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

the class ConfigurationPropertiesTests method loadWhenBeanFactoryContainsSingletonForConstructorBindingTypeShouldNotFail.

// gh-18652
@Test
void loadWhenBeanFactoryContainsSingletonForConstructorBindingTypeShouldNotFail() {
    ConfigurableListableBeanFactory beanFactory = this.context.getBeanFactory();
    ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition("test", new RootBeanDefinition(ConstructorParameterProperties.class));
    beanFactory.registerSingleton("test", new ConstructorParameterProperties("bar", 5));
    load(TestConfiguration.class);
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.jupiter.api.Test)

Example 63 with BeanDefinitionRegistry

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

the class SharedMetadataReaderFactoryContextInitializerTests method initializeWhenUsingSupplierDecorates.

@Test
void initializeWhenUsingSupplierDecorates() {
    GenericApplicationContext context = new GenericApplicationContext();
    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) context.getBeanFactory();
    ConfigurationClassPostProcessor configurationAnnotationPostProcessor = mock(ConfigurationClassPostProcessor.class);
    BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(ConfigurationClassPostProcessor.class).getBeanDefinition();
    ((AbstractBeanDefinition) beanDefinition).setInstanceSupplier(() -> configurationAnnotationPostProcessor);
    registry.registerBeanDefinition(AnnotationConfigUtils.CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME, beanDefinition);
    CachingMetadataReaderFactoryPostProcessor postProcessor = new CachingMetadataReaderFactoryPostProcessor(context);
    postProcessor.postProcessBeanDefinitionRegistry(registry);
    context.refresh();
    ConfigurationClassPostProcessor bean = context.getBean(ConfigurationClassPostProcessor.class);
    assertThat(bean).isSameAs(configurationAnnotationPostProcessor);
    ArgumentCaptor<MetadataReaderFactory> metadataReaderFactory = ArgumentCaptor.forClass(MetadataReaderFactory.class);
    then(configurationAnnotationPostProcessor).should().setMetadataReaderFactory(metadataReaderFactory.capture());
    assertThat(metadataReaderFactory.getValue()).isInstanceOf(ConcurrentReferenceCachingMetadataReaderFactory.class);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) ConcurrentReferenceCachingMetadataReaderFactory(org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) ConfigurationClassPostProcessor(org.springframework.context.annotation.ConfigurationClassPostProcessor) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) CachingMetadataReaderFactoryPostProcessor(org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer.CachingMetadataReaderFactoryPostProcessor) Test(org.junit.jupiter.api.Test)

Example 64 with BeanDefinitionRegistry

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

the class ServletManagementContextFactory method registerServletWebServerFactory.

private void registerServletWebServerFactory(ApplicationContext parent, AnnotationConfigServletWebServerApplicationContext childContext) {
    try {
        ConfigurableListableBeanFactory beanFactory = childContext.getBeanFactory();
        if (beanFactory instanceof BeanDefinitionRegistry) {
            BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
            registry.registerBeanDefinition("ServletWebServerFactory", new RootBeanDefinition(determineServletWebServerFactoryClass(parent)));
        }
    } catch (NoSuchBeanDefinitionException ex) {
    // Ignore and assume auto-configuration
    }
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 65 with BeanDefinitionRegistry

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

the class ReactiveManagementContextFactory method registerReactiveWebServerFactory.

private void registerReactiveWebServerFactory(ApplicationContext parent, AnnotationConfigReactiveWebServerApplicationContext childContext) {
    try {
        ConfigurableListableBeanFactory beanFactory = childContext.getBeanFactory();
        if (beanFactory instanceof BeanDefinitionRegistry) {
            BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
            registry.registerBeanDefinition("ReactiveWebServerFactory", new RootBeanDefinition(determineReactiveWebServerFactoryClass(parent)));
        }
    } catch (NoSuchBeanDefinitionException ex) {
    // Ignore and assume auto-configuration
    }
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

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