Package org.springframework.beans.factory

Examples of org.springframework.beans.factory.NoSuchBeanDefinitionException


        ConnectorObject after = null;

        try {
            final ConnectorFacadeProxy connector = connLoader.getConnector(task.getResource());
            if (connector == null) {
                throw new NoSuchBeanDefinitionException(String.format(
                        "Connector instance bean for resource %s not found", task.getResource()));
            }

            // Try to read user BEFORE any actual operation
            before = getRemoteObject(connector, task, false);
View Full Code Here


            ((ConfigurableBeanFactory) beanFactory).registerDependentBean(this.beanName, requestingBeanName);
          }
          return bean;
        }
        else if (this.isDefaultName && !StringUtils.hasLength(this.mappedName)) {
          throw new NoSuchBeanDefinitionException(this.beanName,
              "Cannot resolve 'beanName' in local BeanFactory. Consider specifying a general 'name' value instead.");
        }
      }
      // JNDI name lookup - may still go to a local BeanFactory.
      return getResource(this, requestingBeanName);
View Full Code Here

    if (this.alwaysUseJndiLookup) {
      return this.jndiFactory.getBean(name, type);
    }

    if (this.resourceFactory == null) {
      throw new NoSuchBeanDefinitionException(type, "No resource factory configured - " +
          "override the getResource method or specify the 'resourceFactory' property");
    }

    if (this.fallbackToDefaultTypeMatch && resourceElement.isDefaultName &&
        this.resourceFactory instanceof AutowireCapableBeanFactory && !this.resourceFactory.containsBean(name)) {
View Full Code Here

            else {
              if (getParentBeanFactory() instanceof ConfigurableBeanFactory) {
                pbd = ((ConfigurableBeanFactory) getParentBeanFactory()).getMergedBeanDefinition(parentBeanName);
              }
              else {
                throw new NoSuchBeanDefinitionException(bd.getParentName(),
                    "Parent name '" + bd.getParentName() + "' is equal to bean name '" + beanName +
                    "': cannot be resolved without an AbstractBeanFactory parent");
              }
            }
          }
View Full Code Here

  public Object getBean(String name) throws BeansException {
    String beanName = BeanFactoryUtils.transformedBeanName(name);
    Object bean = this.beans.get(beanName);

    if (bean == null) {
      throw new NoSuchBeanDefinitionException(beanName,
          "Defined beans are [" + StringUtils.collectionToCommaDelimitedString(this.beans.keySet()) + "]");
    }

    // Don't let calling code try to dereference the
    // bean factory if the bean isn't a factory
View Full Code Here

  public Class getType(String name) throws NoSuchBeanDefinitionException {
    String beanName = BeanFactoryUtils.transformedBeanName(name);

    Object bean = this.beans.get(beanName);
    if (bean == null) {
      throw new NoSuchBeanDefinitionException(beanName,
          "Defined beans are [" + StringUtils.collectionToCommaDelimitedString(this.beans.keySet()) + "]");
    }

    if (bean instanceof FactoryBean && !BeanFactoryUtils.isFactoryDereference(name)) {
      // If it's a FactoryBean, we want to look at what it creates, not the factory class.
View Full Code Here

    for (Iterator it = candidateBeans.entrySet().iterator(); it.hasNext();) {
      Map.Entry entry = (Map.Entry) it.next();
      String candidateBeanName = (String) entry.getKey();
      if (isPrimary(candidateBeanName, entry.getValue())) {
        if (primaryBeanName != null) {
          throw new NoSuchBeanDefinitionException(type,
              "more than one 'primary' bean found among candidates: " + candidateBeans.keySet());
        }
        primaryBeanName = candidateBeanName;
      }
    }
View Full Code Here

    BeanDefinition bd = (BeanDefinition) this.beanDefinitionMap.get(beanName);
    if (bd == null) {
      if (this.logger.isTraceEnabled()) {
        this.logger.trace("No bean named '" + beanName + "' found in " + this);
      }
      throw new NoSuchBeanDefinitionException(beanName);
    }
    return bd;
  }
View Full Code Here

      BeanDefinition bd = (BeanDefinition) this.beanDefinitionMap.remove(beanName);
      if (bd == null) {
        if (this.logger.isTraceEnabled()) {
          this.logger.trace("No bean named '" + beanName + "' found in " + this);
        }
        throw new NoSuchBeanDefinitionException(beanName);
      }
      this.beanDefinitionNames.remove(beanName);

      resetBeanDefinition(beanName);
    }
View Full Code Here

    if (type.isArray()) {
      Class componentType = type.getComponentType();
      Map matchingBeans = findAutowireCandidates(beanName, componentType, descriptor);
      if (matchingBeans.isEmpty()) {
        if (descriptor.isRequired()) {
          throw new NoSuchBeanDefinitionException(componentType,
              "Unsatisfied dependency of type [" + componentType + "]: expected at least 1 matching bean");
        }
        return null;
      }
      if (autowiredBeanNames != null) {
        autowiredBeanNames.addAll(matchingBeans.keySet());
      }
      TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
      return converter.convertIfNecessary(matchingBeans.values(), type);
    }
    else if (Collection.class.isAssignableFrom(type) && type.isInterface()) {
      Class elementType = descriptor.getCollectionType();
      if (elementType == null) {
        if (descriptor.isRequired()) {
          throw new FatalBeanException("No element type declared for collection");
        }
        return null;
      }
      Map matchingBeans = findAutowireCandidates(beanName, elementType, descriptor);
      if (matchingBeans.isEmpty()) {
        if (descriptor.isRequired()) {
          throw new NoSuchBeanDefinitionException(elementType,
              "Unsatisfied dependency of type [" + elementType.getName() + "]: expected at least 1 matching bean");
        }
        return null;
      }
      if (autowiredBeanNames != null) {
        autowiredBeanNames.addAll(matchingBeans.keySet());
      }
      TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
      return converter.convertIfNecessary(matchingBeans.values(), type);
    }
    else if (Map.class.isAssignableFrom(type) && type.isInterface()) {
      Class keyType = descriptor.getMapKeyType();
      if (keyType == null || !String.class.isAssignableFrom(keyType)) {
        if (descriptor.isRequired()) {
          throw new FatalBeanException("Map key type must be assignable to [" + String.class.getName() + "]");
        }
        return null;
      }
      Class valueType = descriptor.getMapValueType();
      if (valueType == null) {
        if (descriptor.isRequired()) {
          throw new FatalBeanException("No value type declared for map");
        }
        return null;
      }
      Map matchingBeans = findAutowireCandidates(beanName, valueType, descriptor);
      if (matchingBeans.isEmpty()) {
        if (descriptor.isRequired()) {
          throw new NoSuchBeanDefinitionException(valueType,
              "Unsatisfied dependency of type [" + valueType.getName() + "]: expected at least 1 matching bean");
        }
        return null;
      }
      if (autowiredBeanNames != null) {
        autowiredBeanNames.addAll(matchingBeans.keySet());
      }
      return matchingBeans;
    }
    else {
      Map matchingBeans = findAutowireCandidates(beanName, type, descriptor);
      if (matchingBeans.isEmpty()) {
        if (descriptor.isRequired()) {
          throw new NoSuchBeanDefinitionException(type,
              "Unsatisfied dependency of type [" + type + "]: expected at least 1 matching bean");
        }
        return null;
      }
      if (matchingBeans.size() > 1) {
        String primaryBeanName = determinePrimaryCandidate(matchingBeans, type);
        if (primaryBeanName == null) {
          throw new NoSuchBeanDefinitionException(type,
              "expected single matching bean but found " + matchingBeans.size() + ": " + matchingBeans.keySet());
        }
        if (autowiredBeanNames != null) {
          autowiredBeanNames.add(primaryBeanName);
        }
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.NoSuchBeanDefinitionException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.