List of usage examples for org.springframework.beans.factory.support RootBeanDefinition isAbstract
@Override public boolean isAbstract()
From source file:org.sakaiproject.util.NoisierDefaultListableBeanFactory.java
public void preInstantiateSingletons() throws BeansException { if (logger.isDebugEnabled()) { logger.debug("Pre-instantiating singletons in factory [" + this + "]"); }//from w w w. j av a 2 s . c o m // The superclass's variable by this name is declared private. String[] beanDefinitionNames = getBeanDefinitionNames(); String beanName = null; // Remember in case of an exception try { // for (Iterator it = this.beanDefinitionNames.iterator(); it.hasNext();) { for (int i = 0; i < beanDefinitionNames.length; i++) { beanName = beanDefinitionNames[i]; if (!containsSingleton(beanName) && containsBeanDefinition(beanName)) { RootBeanDefinition bd = getMergedBeanDefinition(beanName, false); if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) { if (bd.hasBeanClass() && FactoryBean.class.isAssignableFrom(bd.getBeanClass())) { FactoryBean factory = (FactoryBean) getBean(FACTORY_BEAN_PREFIX + beanName); if (factory.isSingleton()) { getBean(beanName); } } else { getBean(beanName); } } } } } catch (BeansException ex) { // Destroy already created singletons to avoid dangling resources. logger.error( "Failed to preinstantiate the singleton named " + beanName + ". Destroying all Spring beans.", ex); try { destroySingletons(); } catch (Throwable ex2) { logger.error( "Pre-instantiating singletons failed, " + "and couldn't destroy already created singletons", ex2); } throw ex; } }
From source file:org.springframework.beans.factory.support.AbstractBeanFactory.java
/** * Check the given merged bean definition, * potentially throwing validation exceptions. * @param mergedBeanDefinition the bean definition to check * @param beanName the name of the bean/*from w w w . ja v a 2 s . c om*/ * @param requiredType the required type of the bean * @param args the arguments for bean creation, if any * @throws BeansException in case of validation failure */ protected void checkMergedBeanDefinition(RootBeanDefinition mergedBeanDefinition, String beanName, Class requiredType, Object[] args) throws BeansException { // check if bean definition is not abstract if (mergedBeanDefinition.isAbstract()) { throw new BeanIsAbstractException(beanName); } // Check if required type can match according to the bean definition. // This is only possible at this early stage for conventional beans! if (mergedBeanDefinition.hasBeanClass()) { Class beanClass = mergedBeanDefinition.getBeanClass(); if (requiredType != null && mergedBeanDefinition.getFactoryMethodName() == null && !FactoryBean.class.isAssignableFrom(beanClass) && !requiredType.isAssignableFrom(beanClass)) { throw new BeanNotOfRequiredTypeException(beanName, requiredType, beanClass); } } // Check validity of the usage of the args parameter. This can // only be used for prototypes constructed via a factory method. if (args != null) { if (mergedBeanDefinition.isSingleton()) { throw new BeanDefinitionStoreException( "Cannot specify arguments in the getBean() method when referring to a singleton bean definition"); } else if (mergedBeanDefinition.getFactoryMethodName() == null) { throw new BeanDefinitionStoreException( "Can only specify arguments in the getBean() method in conjunction with a factory method"); } } }