Search in sources :

Example 76 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project wicket by apache.

the class SpringBeanLocator method getBeanDefinition.

/**
 * Gets the root bean definition for the given name.
 *
 * @param ctx
 * 				spring application context.
 * @param name
 * 				bean name
 * @return bean definition for the current name, null if such a definition is not found.
 */
public RootBeanDefinition getBeanDefinition(final ApplicationContext ctx, final String name) {
    ConfigurableListableBeanFactory beanFactory = ((AbstractApplicationContext) ctx).getBeanFactory();
    BeanDefinition beanDef = beanFactory.containsBean(name) ? beanFactory.getMergedBeanDefinition(name) : null;
    if (beanDef instanceof RootBeanDefinition) {
        return (RootBeanDefinition) beanDef;
    }
    return null;
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 77 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-cloud-gcp by spring-cloud.

the class AbstractSpannerIntegrationTest method createDatabaseWithSchema.

protected void createDatabaseWithSchema() {
    this.tableNameSuffix = String.valueOf(System.currentTimeMillis());
    ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) this.applicationContext).getBeanFactory();
    beanFactory.registerSingleton("tableNameSuffix", this.tableNameSuffix);
    String instanceId = this.databaseId.getInstanceId().getInstance();
    String database = this.databaseId.getDatabase();
    if (!hasDatabaseDefined(instanceId, database)) {
        this.databaseAdminClient.createDatabase(instanceId, database, createSchemaStatements()).waitFor();
        System.out.println(this.getClass() + " - Integration database created with schema: " + createSchemaStatements());
    } else {
        this.databaseAdminClient.updateDatabaseDdl(instanceId, database, createSchemaStatements(), null).waitFor();
        System.out.println(this.getClass() + " - schema created: " + createSchemaStatements());
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 78 with ConfigurableListableBeanFactory

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

the class SpringInitDestroyVerficationTest method testDestroyMethodCalls.

@Test
public void testDestroyMethodCalls() {
    XmlWebApplicationContext context = (XmlWebApplicationContext) applicationContext;
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    Map<String, Destroyable> beans = applicationContext.getBeansOfType(Destroyable.class);
    for (Iterator<String> iterator = beans.keySet().iterator(); iterator.hasNext(); ) {
        String beanName = iterator.next();
        try {
            GenericBeanDefinition beanDef = (GenericBeanDefinition) beanFactory.getBeanDefinition(beanName);
            assertNotNull("Spring Bean (" + beanName + ") of type Destroyable does not have the required destroy-method attribute or the method name is not destroy!", beanDef.getDestroyMethodName());
            if (beanDef.getDestroyMethodName() != null) {
                assertTrue("Spring Bean (" + beanName + ") of type Destroyable does not have the required destroy-method attribute or the method name is not destroy!", beanDef.getDestroyMethodName().equals("destroy"));
            }
        } catch (NoSuchBeanDefinitionException e) {
            log.error("testDestroyMethodCalls: Error while trying to analyze bean with name: " + beanName + " :" + e);
        } catch (Exception e) {
            log.error("testDestroyMethodCalls: Error while trying to analyze bean with name: " + beanName + " :" + e);
        }
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) Destroyable(org.olat.core.configuration.Destroyable) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 79 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project openolat by klemens.

the class SpringInitDestroyVerficationTest method testDestroyMethodCalls.

@Test
public void testDestroyMethodCalls() {
    XmlWebApplicationContext context = (XmlWebApplicationContext) applicationContext;
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    Map<String, Destroyable> beans = applicationContext.getBeansOfType(Destroyable.class);
    for (Iterator<String> iterator = beans.keySet().iterator(); iterator.hasNext(); ) {
        String beanName = iterator.next();
        try {
            GenericBeanDefinition beanDef = (GenericBeanDefinition) beanFactory.getBeanDefinition(beanName);
            assertNotNull("Spring Bean (" + beanName + ") of type Destroyable does not have the required destroy-method attribute or the method name is not destroy!", beanDef.getDestroyMethodName());
            if (beanDef.getDestroyMethodName() != null) {
                assertTrue("Spring Bean (" + beanName + ") of type Destroyable does not have the required destroy-method attribute or the method name is not destroy!", beanDef.getDestroyMethodName().equals("destroy"));
            }
        } catch (NoSuchBeanDefinitionException e) {
            log.error("testDestroyMethodCalls: Error while trying to analyze bean with name: " + beanName + " :" + e);
        } catch (Exception e) {
            log.error("testDestroyMethodCalls: Error while trying to analyze bean with name: " + beanName + " :" + e);
        }
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) Destroyable(org.olat.core.configuration.Destroyable) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 80 with ConfigurableListableBeanFactory

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

the class DefaultLifecycleProcessor method getLifecycleBeans.

// overridable hooks
/**
 * Retrieve all applicable Lifecycle beans: all singletons that have already been created,
 * as well as all SmartLifecycle beans (even if they are marked as lazy-init).
 * @return the Map of applicable beans, with bean names as keys and bean instances as values
 */
protected Map<String, Lifecycle> getLifecycleBeans() {
    ConfigurableListableBeanFactory beanFactory = getBeanFactory();
    Map<String, Lifecycle> beans = new LinkedHashMap<>();
    String[] beanNames = beanFactory.getBeanNamesForType(Lifecycle.class, false, false);
    for (String beanName : beanNames) {
        String beanNameToRegister = BeanFactoryUtils.transformedBeanName(beanName);
        boolean isFactoryBean = beanFactory.isFactoryBean(beanNameToRegister);
        String beanNameToCheck = (isFactoryBean ? BeanFactory.FACTORY_BEAN_PREFIX + beanName : beanName);
        if ((beanFactory.containsSingleton(beanNameToRegister) && (!isFactoryBean || matchesBeanType(Lifecycle.class, beanNameToCheck, beanFactory))) || matchesBeanType(SmartLifecycle.class, beanNameToCheck, beanFactory)) {
            Object bean = beanFactory.getBean(beanNameToCheck);
            if (bean != this && bean instanceof Lifecycle) {
                beans.put(beanNameToRegister, (Lifecycle) bean);
            }
        }
    }
    return beans;
}
Also used : Lifecycle(org.springframework.context.Lifecycle) SmartLifecycle(org.springframework.context.SmartLifecycle) SmartLifecycle(org.springframework.context.SmartLifecycle) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) LinkedHashMap(java.util.LinkedHashMap)

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