Package org.springframework.beans.factory

Examples of org.springframework.beans.factory.BeanCreationException


    PropertyValues pvs = mbd.getPropertyValues();

    if (bw == null) {
      if (!pvs.isEmpty()) {
        throw new BeanCreationException(
            mbd.getResourceDescription(), beanName, "Cannot apply property values to null instance");
      }
      else {
        // Skip property population phase for null instance.
        return;
View Full Code Here


        try {
          bw.setPropertyValues(mpvs);
          return;
        }
        catch (BeansException ex) {
          throw new BeanCreationException(
              mbd.getResourceDescription(), beanName, "Error setting property values", ex);
        }
      }
      original = mpvs.getPropertyValueList();
    }
    else {
      original = Arrays.asList(pvs.getPropertyValues());
    }

    TypeConverter converter = getCustomTypeConverter();
    if (converter == null) {
      converter = bw;
    }
    BeanDefinitionValueResolver valueResolver = new BeanDefinitionValueResolver(this, beanName, mbd, converter);

    // Create a deep copy, resolving any references for values.
    List deepCopy = new ArrayList(original.size());
    boolean resolveNecessary = false;
    for (Iterator it = original.iterator(); it.hasNext();) {
      PropertyValue pv = (PropertyValue) it.next();
      if (pv.isConverted()) {
        deepCopy.add(pv);
      }
      else {
        String propertyName = pv.getName();
        Object originalValue = pv.getValue();
        Object resolvedValue = valueResolver.resolveValueIfNecessary(pv, originalValue);
        // Possibly store converted value in merged bean definition,
        // in order to avoid re-conversion for every created bean instance.
        if (resolvedValue == originalValue) {
          if (!PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName)) {
            pv.setConvertedValue(convertForProperty(resolvedValue, propertyName, bw, converter));
          }
          deepCopy.add(pv);
        }
        else if (originalValue instanceof TypedStringValue &&
            !PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName)) {
          pv.setConvertedValue(convertForProperty(resolvedValue, propertyName, bw, converter));
          deepCopy.add(pv);
        }
        else {
          resolveNecessary = true;
          deepCopy.add(new PropertyValue(pv, resolvedValue));
        }
      }
    }
    if (mpvs != null && !resolveNecessary) {
      mpvs.setConverted();
    }

    // Set our (possibly massaged) deep copy.
    try {
      bw.setPropertyValues(new MutablePropertyValues(deepCopy));
    }
    catch (BeansException ex) {
      throw new BeanCreationException(
          mbd.getResourceDescription(), beanName, "Error setting property values", ex);
    }
  }
View Full Code Here

    try {
      invokeInitMethods(beanName, wrappedBean, mbd);
    }
    catch (Throwable ex) {
      throw new BeanCreationException(
          (mbd != null ? mbd.getResourceDescription() : null),
          beanName, "Invocation of init method failed", ex);
    }

    if (mbd == null || !mbd.isSynthetic()) {
View Full Code Here

          // Already found greedy constructor that can be satisfied ->
          // do not look any further, there are only less greedy constructors left.
          break;
        }
        if (paramTypes.length < minNrOfArgs) {
          throw new BeanCreationException(mbd.getResourceDescription(), beanName,
              minNrOfArgs + " constructor arguments specified but no matching constructor found in bean '" +
              beanName + "' " +
              "(hint: specify index and/or type arguments for simple parameters to avoid type ambiguities)");
        }

        ArgumentsHolder args = null;

        if (resolvedValues != null) {
          // Try to resolve arguments for current constructor.
          try {
            args = createArgumentArray(
                beanName, mbd, resolvedValues, bw, paramTypes, candidate, autowiring);
          }
          catch (UnsatisfiedDependencyException ex) {
            if (this.beanFactory.logger.isTraceEnabled()) {
              this.beanFactory.logger.trace(
                  "Ignoring constructor [" + candidate + "] of bean '" + beanName + "': " + ex);
            }
            if (i == candidates.length - 1 && constructorToUse == null) {
              throw ex;
            }
            else {
              // Swallow and try next constructor.
              this.beanFactory.onSuppressedException(ex);
              continue;
            }
          }
        }

        else {
          // Explicit arguments given -> arguments length must match exactly.
          if (paramTypes.length != explicitArgs.length) {
            continue;
          }
          args = new ArgumentsHolder(explicitArgs);
        }

        int typeDiffWeight = args.getTypeDifferenceWeight(paramTypes);
        // Choose this constructor if it represents the closest match.
        if (typeDiffWeight < minTypeDiffWeight) {
          constructorToUse = candidate;
          argsToUse = args.arguments;
          minTypeDiffWeight = typeDiffWeight;
        }
      }

      if (constructorToUse == null) {
        throw new BeanCreationException(
            mbd.getResourceDescription(), beanName, "Could not resolve matching constructor");
      }

      if (explicitArgs == null) {
        mbd.resolvedConstructorOrFactoryMethod = constructorToUse;
      }
    }

    try {
      Object beanInstance = this.instantiationStrategy.instantiate(
          mbd, beanName, this.beanFactory, constructorToUse, argsToUse);
      bw.setWrappedInstance(beanInstance);
      return bw;
    }
    catch (Throwable ex) {
      throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Instantiation of bean failed", ex);
    }
  }
View Full Code Here

          }
        }
      }

      if (factoryMethodToUse == null) {
        throw new BeanCreationException(
            mbd.getResourceDescription(), beanName,
            "No matching factory method found: " +
            (mbd.getFactoryBeanName() != null ?
             "factory bean '" + mbd.getFactoryBeanName() + "'; " : "") +
            "factory method '" + mbd.getFactoryMethodName() + "'");
      }

      if (explicitArgs == null) {
        mbd.resolvedConstructorOrFactoryMethod = factoryMethodToUse;
      }
    }

    try {
      Object beanInstance = this.instantiationStrategy.instantiate(
          mbd, beanName, this.beanFactory, factoryBean, factoryMethodToUse, argsToUse);
      if (beanInstance == null) {
        return null;
      }
      bw.setWrappedInstance(beanInstance);
      return bw;
    }
    catch (Throwable ex) {
      throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Instantiation of bean failed", ex);
    }
  }
View Full Code Here

    for (Iterator it = cargs.getIndexedArgumentValues().entrySet().iterator(); it.hasNext();) {
      Map.Entry entry = (Map.Entry) it.next();
      int index = ((Integer) entry.getKey()).intValue();
      if (index < 0) {
        throw new BeanCreationException(mbd.getResourceDescription(), beanName,
            "Invalid constructor argument index: " + index);
      }
      if (index > minNrOfArgs) {
        minNrOfArgs = index + 1;
      }
View Full Code Here

        try {
            props = PropertiesLoaderUtils.loadProperties(new ClassPathResource("beaninterfaces.properties"));
            log.debug("Properties: " +  props);
        }
        catch (IOException e1) {
            throw new BeanCreationException("Unable to load properties file beaninterfaces.properties", e1);
        }
        return props;
    }
View Full Code Here

        this.initParameters = (initParameters != null ? new HashMap<String, String>(initParameters) : new HashMap<String, String>());
       
        if (servletName == null) {
            if (moduleDefintion == null) {
                throw new BeanCreationException("No servlet name provide, and module definition is null");
            }
            servletName = moduleDefintion.getName();
        }
       
        servlet = ObjectUtils.cast(BeanUtils.instantiateClass(servletClass), Servlet.class);
View Full Code Here

          Constructor<?> defaultConstructor = null;
          for (Constructor<?> candidate : rawCandidates) {
            Annotation annotation = findAutowiredAnnotation(candidate);
            if (annotation != null) {
              if (requiredConstructor != null) {
                throw new BeanCreationException("Invalid autowire-marked constructor: " + candidate +
                    ". Found another constructor with 'required' Autowired annotation: " +
                    requiredConstructor);
              }
              if (candidate.getParameterTypes().length == 0) {
                throw new IllegalStateException(
                    "Autowired annotation requires at least one argument: " + candidate);
              }
              boolean required = determineRequiredStatus(annotation);
              if (required) {
                if (!candidates.isEmpty()) {
                  throw new BeanCreationException(
                      "Invalid autowire-marked constructors: " + candidates +
                      ". Found another constructor with 'required' Autowired annotation: " +
                      requiredConstructor);
                }
                requiredConstructor = candidate;
View Full Code Here

    InjectionMetadata metadata = findAutowiringMetadata(bean.getClass());
    try {
      metadata.inject(bean, beanName, pvs);
    }
    catch (Throwable ex) {
      throw new BeanCreationException(beanName, "Injection of autowired dependencies failed", ex);
    }
    return pvs;
  }
View Full Code Here

TOP

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

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.