Search in sources :

Example 96 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.

the class SessionAutoConfigurationJdbcTests method sessionRepositoryBeansDependOnFlyway.

@Test
void sessionRepositoryBeansDependOnFlyway() {
    this.contextRunner.withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class)).withPropertyValues("spring.session.store-type=jdbc", "spring.session.jdbc.initialize-schema=never").run((context) -> {
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        String[] sessionRepositoryNames = beanFactory.getBeanNamesForType(JdbcIndexedSessionRepository.class);
        assertThat(sessionRepositoryNames).isNotEmpty();
        for (String sessionRepositoryName : sessionRepositoryNames) {
            assertThat(beanFactory.getBeanDefinition(sessionRepositoryName).getDependsOn()).contains("flyway", "flywayInitializer");
        }
    });
}
Also used : FlywayAutoConfiguration(org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.jupiter.api.Test)

Example 97 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.

the class ShutdownEndpointAutoConfigurationTests method runShouldHaveEndpointBeanThatIsNotDisposable.

@Test
@SuppressWarnings("unchecked")
void runShouldHaveEndpointBeanThatIsNotDisposable() {
    this.contextRunner.withPropertyValues("management.endpoint.shutdown.enabled:true").withPropertyValues("management.endpoints.web.exposure.include=shutdown").run((context) -> {
        assertThat(context).hasSingleBean(ShutdownEndpoint.class);
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        Map<String, Object> disposableBeans = (Map<String, Object>) ReflectionTestUtils.getField(beanFactory, "disposableBeans");
        assertThat(disposableBeans).isEmpty();
    });
}
Also used : Map(java.util.Map) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.jupiter.api.Test)

Example 98 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory 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 99 with ConfigurableListableBeanFactory

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

Example 100 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project dubbo by alibaba.

the class ReferenceAnnotationBeanPostProcessor method registerReferenceBean.

/**
 * Register an instance of {@link ReferenceBean} as a Spring Bean
 *
 * @param referencedBeanName The name of bean that annotated Dubbo's {@link Service @Service} in the Spring {@link ApplicationContext}
 * @param referenceBean      the instance of {@link ReferenceBean} is about to register into the Spring {@link ApplicationContext}
 * @param attributes         the {@link AnnotationAttributes attributes} of {@link Reference @Reference}
 * @param localServiceBean   Is Local Service bean or not
 * @param interfaceClass     the {@link Class class} of Service interface
 * @since 2.7.3
 */
private void registerReferenceBean(String referencedBeanName, ReferenceBean referenceBean, boolean localServiceBean, String beanName) {
    ConfigurableListableBeanFactory beanFactory = getBeanFactory();
    if (localServiceBean) {
        // If @Service bean is local one
        /**
         * Get  the @Service's BeanDefinition from {@link BeanFactory}
         * Refer to {@link ServiceClassPostProcessor#buildServiceBeanDefinition}
         */
        AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) beanFactory.getBeanDefinition(referencedBeanName);
        RuntimeBeanReference runtimeBeanReference = (RuntimeBeanReference) beanDefinition.getPropertyValues().get("ref");
        // The name of bean annotated @Service
        String serviceBeanName = runtimeBeanReference.getBeanName();
        // register Alias rather than a new bean name, in order to reduce duplicated beans
        beanFactory.registerAlias(serviceBeanName, beanName);
    } else {
        // Remote @Service Bean
        if (!beanFactory.containsBean(beanName)) {
            beanFactory.registerSingleton(beanName, referenceBean);
        }
    }
}
Also used : AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Aggregations

ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)104 Test (org.junit.Test)16 Test (org.junit.jupiter.api.Test)15 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)13 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)12 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)10 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)10 ApplicationContext (org.springframework.context.ApplicationContext)9 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)8 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)7 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)7 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)7 Map (java.util.Map)6 BeanFactory (org.springframework.beans.factory.BeanFactory)6 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)6 Collectors (java.util.stream.Collectors)5 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 HashMap (java.util.HashMap)4 BeanFactoryPostProcessor (org.springframework.beans.factory.config.BeanFactoryPostProcessor)4 SimpleApplicationEventMulticaster (org.springframework.context.event.SimpleApplicationEventMulticaster)4