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 + "]");
}
}
}
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;
}
Aggregations