Search in sources :

Example 31 with ConfigurableListableBeanFactory

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

the class AbstractApplicationContext method initLifecycleProcessor.

/**
	 * Initialize the LifecycleProcessor.
	 * Uses DefaultLifecycleProcessor if none defined in the context.
	 * @see org.springframework.context.support.DefaultLifecycleProcessor
	 */
protected void initLifecycleProcessor() {
    ConfigurableListableBeanFactory beanFactory = getBeanFactory();
    if (beanFactory.containsLocalBean(LIFECYCLE_PROCESSOR_BEAN_NAME)) {
        this.lifecycleProcessor = beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class);
        if (logger.isDebugEnabled()) {
            logger.debug("Using LifecycleProcessor [" + this.lifecycleProcessor + "]");
        }
    } else {
        DefaultLifecycleProcessor defaultProcessor = new DefaultLifecycleProcessor();
        defaultProcessor.setBeanFactory(beanFactory);
        this.lifecycleProcessor = defaultProcessor;
        beanFactory.registerSingleton(LIFECYCLE_PROCESSOR_BEAN_NAME, this.lifecycleProcessor);
        if (logger.isDebugEnabled()) {
            logger.debug("Unable to locate LifecycleProcessor with name '" + LIFECYCLE_PROCESSOR_BEAN_NAME + "': using default [" + this.lifecycleProcessor + "]");
        }
    }
}
Also used : ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) LifecycleProcessor(org.springframework.context.LifecycleProcessor)

Example 32 with ConfigurableListableBeanFactory

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

the class IgniteSpringHelperImpl method prepareSpringContext.

/**
     * Prepares Spring context.
     *
     * @param excludedProps Properties to be excluded.
     * @return application context.
     */
private static GenericApplicationContext prepareSpringContext(final String... excludedProps) {
    GenericApplicationContext springCtx = new GenericApplicationContext();
    if (excludedProps.length > 0) {
        final List<String> excludedPropsList = Arrays.asList(excludedProps);
        BeanFactoryPostProcessor postProc = new BeanFactoryPostProcessor() {

            /**
                 * @param def Registered BeanDefinition.
                 * @throws BeansException in case of errors.
                 */
            private void processNested(BeanDefinition def) throws BeansException {
                Iterator<PropertyValue> iterVals = def.getPropertyValues().getPropertyValueList().iterator();
                while (iterVals.hasNext()) {
                    PropertyValue val = iterVals.next();
                    if (excludedPropsList.contains(val.getName())) {
                        iterVals.remove();
                        continue;
                    }
                    if (val.getValue() instanceof Iterable) {
                        Iterator iterNested = ((Iterable) val.getValue()).iterator();
                        while (iterNested.hasNext()) {
                            Object item = iterNested.next();
                            if (item instanceof BeanDefinitionHolder) {
                                BeanDefinitionHolder h = (BeanDefinitionHolder) item;
                                try {
                                    if (h.getBeanDefinition().getBeanClassName() != null)
                                        Class.forName(h.getBeanDefinition().getBeanClassName());
                                    processNested(h.getBeanDefinition());
                                } catch (ClassNotFoundException ignored) {
                                    iterNested.remove();
                                }
                            }
                        }
                    }
                }
            }

            @Override
            public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
                for (String beanName : beanFactory.getBeanDefinitionNames()) {
                    try {
                        BeanDefinition def = beanFactory.getBeanDefinition(beanName);
                        if (def.getBeanClassName() != null)
                            Class.forName(def.getBeanClassName());
                        processNested(def);
                    } catch (ClassNotFoundException ignored) {
                        ((BeanDefinitionRegistry) beanFactory).removeBeanDefinition(beanName);
                    }
                }
            }
        };
        springCtx.addBeanFactoryPostProcessor(postProc);
    }
    return springCtx;
}
Also used : PropertyValue(org.springframework.beans.PropertyValue) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) Iterator(java.util.Iterator) BeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Aggregations

ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)32 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)5 BeanFactoryPostProcessor (org.springframework.beans.factory.config.BeanFactoryPostProcessor)4 ApplicationContext (org.springframework.context.ApplicationContext)4 Test (org.junit.Test)3 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)3 CloudFactory (org.springframework.cloud.CloudFactory)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 BeansException (org.springframework.beans.BeansException)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)2 GrailsPlugin (grails.plugins.GrailsPlugin)1 ConfigObject (groovy.util.ConfigObject)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 ServletContext (javax.servlet.ServletContext)1 MultifactorAuthenticationProperties (org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProperties)1 NavigableMap (org.grails.config.NavigableMap)1