List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory getParentBeanFactory
@Nullable BeanFactory getParentBeanFactory();
From source file:io.github.hzpz.spring.boot.autoconfigure.mongeez.MongoDbFactoryDependsOnPostProcessor.java
private static BeanDefinition getBeanDefinition(String beanName, ConfigurableListableBeanFactory beanFactory) { try {/*from w w w .j a v a 2 s. c om*/ return beanFactory.getBeanDefinition(beanName); } catch (NoSuchBeanDefinitionException ex) { BeanFactory parentBeanFactory = beanFactory.getParentBeanFactory(); if (parentBeanFactory instanceof ConfigurableListableBeanFactory) { return getBeanDefinition(beanName, (ConfigurableListableBeanFactory) parentBeanFactory); } throw ex; } }
From source file:uk.org.ponder.rsac.support.BeanDefUtil.java
static AbstractBeanDefinition getMergedBeanDefinition(ConfigurableListableBeanFactory factory, String beanName, boolean includingAncestors) throws BeansException { try {//from w w w.jav a 2 s . c om return getMergedBeanDefinition(factory, beanName, factory.getBeanDefinition(beanName)); } catch (NoSuchBeanDefinitionException ex) { if (includingAncestors && factory.getParentBeanFactory() instanceof ConfigurableListableBeanFactory) { return getMergedBeanDefinition((ConfigurableListableBeanFactory) factory.getParentBeanFactory(), beanName, true); } else { throw ex; } } }
From source file:lodsve.core.condition.ConditionEvaluationReport.java
/** * Obtain a {@link ConditionEvaluationReport} for the specified bean factory. * * @param beanFactory the bean factory/*from ww w.j av a2s .co m*/ * @return an existing or new {@link ConditionEvaluationReport} */ public static ConditionEvaluationReport get(ConfigurableListableBeanFactory beanFactory) { synchronized (beanFactory) { ConditionEvaluationReport report; if (beanFactory.containsSingleton(BEAN_NAME)) { report = beanFactory.getBean(BEAN_NAME, ConditionEvaluationReport.class); } else { report = new ConditionEvaluationReport(); beanFactory.registerSingleton(BEAN_NAME, report); } locateParent(beanFactory.getParentBeanFactory(), report); return report; } }
From source file:uk.org.ponder.rsac.support.BeanDefUtil.java
static AbstractBeanDefinition getMergedBeanDefinition(ConfigurableListableBeanFactory factory, String beanName, BeanDefinition bd) throws BeansException { if (!(bd instanceof AbstractBeanDefinition)) { throw new IllegalArgumentException("Bean definition " + beanName + " of " + bd.getClass() + " which is not descended from AbstractBeanDefinition can not be recognised"); }/* w w w.j av a2s. c o m*/ AbstractBeanDefinition abd = (AbstractBeanDefinition) bd; String parentName = getParentDefinitionName(abd); if (parentName == null) { return abd; } else { AbstractBeanDefinition pbd = null; if (!beanName.equals(parentName)) { pbd = getMergedBeanDefinition(factory, parentName, true); } else { if (factory.getParentBeanFactory() instanceof ConfigurableListableBeanFactory) { ConfigurableListableBeanFactory parentFactory = (ConfigurableListableBeanFactory) factory .getParentBeanFactory(); pbd = getMergedBeanDefinition(parentFactory, parentName, true); } else { throw new NoSuchBeanDefinitionException(parentName, "Parent name '" + parentName + "' is equal to bean name '" + beanName + "' - cannot be resolved without an AbstractBeanFactory parent"); } } // deep copy with overridden values pbd.overrideFrom(abd); return pbd; } }
From source file:ro.pippo.spring.AnnotationFieldValueProvider.java
private BeanDefinition getBeanDefinition(ConfigurableListableBeanFactory beanFactory, String name) { if (beanFactory.containsBeanDefinition(name)) { return beanFactory.getBeanDefinition(name); }//from w w w .ja va 2 s . c om BeanFactory parent = beanFactory.getParentBeanFactory(); if ((parent != null) && (parent instanceof ConfigurableListableBeanFactory)) { return getBeanDefinition((ConfigurableListableBeanFactory) parent, name); } return null; }
From source file:org.xaloon.wicket.component.inject.spring.CdiProxyFieldValueFactory.java
private BeanDefinition getBeanDefinition(ConfigurableListableBeanFactory beanFactory, String name) { if (beanFactory.containsBeanDefinition(name)) { return beanFactory.getBeanDefinition(name); } else {/*w w w . j a va2 s . co m*/ BeanFactory parent = beanFactory.getParentBeanFactory(); if (parent != null && parent instanceof ConfigurableListableBeanFactory) { return getBeanDefinition((ConfigurableListableBeanFactory) parent, name); } else { return null; } } }
From source file:com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceExporter.java
/** * Find a {@link BeanDefinition} in the {@link BeanFactory} or it's parents. *//*from w ww . j ava2s . c om*/ private BeanDefinition findBeanDefintion(ConfigurableListableBeanFactory beanFactory, String serviceBeanName) { if (beanFactory.containsLocalBean(serviceBeanName)) { return beanFactory.getBeanDefinition(serviceBeanName); } BeanFactory parentBeanFactory = beanFactory.getParentBeanFactory(); if (parentBeanFactory != null && ConfigurableListableBeanFactory.class.isInstance(parentBeanFactory)) { return findBeanDefintion((ConfigurableListableBeanFactory) parentBeanFactory, serviceBeanName); } throw new RuntimeException(format("Bean with name '%s' can no longer be found.", serviceBeanName)); }
From source file:lodsve.core.condition.OnBeanCondition.java
private List<String> getMatchingBeans(ConditionContext context, BeanSearchSpec beans) { ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); if (beans.getStrategy() == SearchStrategy.PARENTS) { BeanFactory parent = beanFactory.getParentBeanFactory(); Assert.isInstanceOf(ConfigurableListableBeanFactory.class, parent, "Unable to use SearchStrategy.PARENTS"); beanFactory = (ConfigurableListableBeanFactory) parent; }//www . java 2 s. com if (beanFactory == null) { return Collections.emptyList(); } List<String> beanNames = new ArrayList<String>(); boolean considerHierarchy = beans.getStrategy() == SearchStrategy.ALL; for (String type : beans.getTypes()) { beanNames.addAll(getBeanNamesForType(beanFactory, type, context.getClassLoader(), considerHierarchy)); } for (String ignoredType : beans.getIgnoredTypes()) { beanNames.removeAll( getBeanNamesForType(beanFactory, ignoredType, context.getClassLoader(), considerHierarchy)); } for (String annotation : beans.getAnnotations()) { beanNames.addAll(Arrays.asList(getBeanNamesForAnnotation(beanFactory, annotation, context.getClassLoader(), considerHierarchy))); } for (String beanName : beans.getNames()) { if (containsBean(beanFactory, beanName, considerHierarchy)) { beanNames.add(beanName); } } return beanNames; }
From source file:lodsve.core.condition.OnBeanCondition.java
private String[] getBeanNamesForAnnotation(ConfigurableListableBeanFactory beanFactory, String type, ClassLoader classLoader, boolean considerHierarchy) throws LinkageError { String[] result = NO_BEANS;// w w w. j a v a 2 s . c o m try { @SuppressWarnings("unchecked") Class<? extends Annotation> typeClass = (Class<? extends Annotation>) ClassUtils.forName(type, classLoader); result = beanFactory.getBeanNamesForAnnotation(typeClass); if (considerHierarchy) { if (beanFactory.getParentBeanFactory() instanceof ConfigurableListableBeanFactory) { String[] parentResult = getBeanNamesForAnnotation( (ConfigurableListableBeanFactory) beanFactory.getParentBeanFactory(), type, classLoader, true); List<String> resultList = new ArrayList<String>(); resultList.addAll(Arrays.asList(result)); for (String beanName : parentResult) { if (!resultList.contains(beanName) && !beanFactory.containsLocalBean(beanName)) { resultList.add(beanName); } } result = StringUtils.toStringArray(resultList); } } return result; } catch (ClassNotFoundException ex) { return NO_BEANS; } }
From source file:com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceExporter.java
/** * Finds the beans to expose and puts them in the {@link #serviceBeanNames} * map./*from w w w . j a va2 s . co m*/ * <p> * Searches parent factories as well. */ private void findServiceBeanDefinitions(ConfigurableListableBeanFactory beanFactory) { for (String beanName : beanFactory.getBeanDefinitionNames()) { JsonRpcService jsonRpcPath = beanFactory.findAnnotationOnBean(beanName, JsonRpcService.class); if (jsonRpcPath != null) { String pathValue = jsonRpcPath.value(); LOG.fine(format("Found JSON-RPC path '%s' for bean [%s].", pathValue, beanName)); if (serviceBeanNames.containsKey(pathValue)) { String otherBeanName = serviceBeanNames.get(pathValue); LOG.warning(format("Duplicate JSON-RPC path specification: found %s on both [%s] and [%s].", pathValue, beanName, otherBeanName)); } serviceBeanNames.put(pathValue, beanName); } } BeanFactory parentBeanFactory = beanFactory.getParentBeanFactory(); if (parentBeanFactory != null && ConfigurableListableBeanFactory.class.isInstance(parentBeanFactory)) { findServiceBeanDefinitions((ConfigurableListableBeanFactory) parentBeanFactory); } }