Package org.springframework.beans.factory

Examples of org.springframework.beans.factory.BeanCreationException


    try {
      String refName = ref.getBeanName();
      refName = String.valueOf(evaluate(refName));
      if (ref.isToParent()) {
        if (this.beanFactory.getParentBeanFactory() == null) {
          throw new BeanCreationException(
              this.beanDefinition.getResourceDescription(), this.beanName,
              "Can't resolve reference to bean '" + refName +
              "' in parent factory: no parent factory available");
        }
        return this.beanFactory.getParentBeanFactory().getBean(refName);
      }
      else {
        Object bean = this.beanFactory.getBean(refName);
        this.beanFactory.registerDependentBean(refName, this.beanName);
        return bean;
      }
    }
    catch (BeansException ex) {
      throw new BeanCreationException(
          this.beanDefinition.getResourceDescription(), this.beanName,
          "Cannot resolve reference to bean '" + ref.getBeanName() + "' while setting " + argName, ex);
    }
  }
View Full Code Here


            }
          });
          bean = getObjectForBeanInstance(scopedInstance, name, beanName, mbd);
        }
        catch (IllegalStateException ex) {
          throw new BeanCreationException(beanName,
              "Scope '" + scopeName + "' is not active for the current thread; " +
              "consider defining a scoped proxy for this bean if you intend to refer to it from a singleton",
              ex);
        }
      }
View Full Code Here

          registrar.registerCustomEditors(registry);
        }
        catch (BeanCreationException ex) {
          Throwable rootCause = ex.getMostSpecificCause();
          if (rootCause instanceof BeanCurrentlyInCreationException) {
            BeanCreationException bce = (BeanCreationException) rootCause;
            if (isCurrentlyInCreation(bce.getBeanName())) {
              if (logger.isDebugEnabled()) {
                logger.debug("PropertyEditorRegistrar [" + registrar.getClass().getName() +
                    "] failed because it tried to obtain currently created bean '" +
                    ex.getBeanName() + "': " + ex.getMessage());
              }
View Full Code Here

    if (bean instanceof FactoryBean && !BeanFactoryUtils.isFactoryDereference(name)) {
      try {
        return ((FactoryBean) bean).getObject();
      }
      catch (Exception ex) {
        throw new BeanCreationException(beanName, "FactoryBean threw exception on object creation", ex);
      }
    }
    else {
      return bean;
    }
View Full Code Here

    }
    catch (FactoryBeanNotInitializedException ex) {
      throw new BeanCurrentlyInCreationException(beanName, ex.toString());
    }
    catch (Throwable ex) {
      throw new BeanCreationException(beanName, "FactoryBean threw exception on object creation", ex);
    }

   
    // Do not accept a null value for a FactoryBean that's not fully
    // initialized yet: Many FactoryBeans just return null then.
    if (object == null && isSingletonCurrentlyInCreation(beanName)) {
      throw new BeanCurrentlyInCreationException(
          beanName, "FactoryBean which is currently in creation returned null from getObject");
    }

    if (object != null && shouldPostProcess) {
      try {
        object = postProcessObjectFromFactoryBean(object, beanName);
      }
      catch (Throwable ex) {
        throw new BeanCreationException(beanName, "Post-processing of the FactoryBean's object failed", ex);
      }
    }

    return object;
  }
View Full Code Here

   * @return the bean instance as FactoryBean
   * @throws BeansException if the given bean cannot be exposed as a FactoryBean
   */
  protected FactoryBean getFactoryBean(String beanName, Object beanInstance) throws BeansException {
    if (!(beanInstance instanceof FactoryBean)) {
      throw new BeanCreationException(beanName,
          "Bean instance of type [" + beanInstance.getClass() + "] is not a FactoryBean");
    }
    return (FactoryBean) beanInstance;
  }
View Full Code Here

      if (scriptedObjectType != null) {
        isFactoryBean = FactoryBean.class.isAssignableFrom(scriptedObjectType);
      }
    }
    catch (Exception e) {
      throw new BeanCreationException("Unable to create scripted object: " + beanName, e);
    }

    long refreshCheckDelay = resolveRefreshCheckDelay(bd);
    if (refreshCheckDelay >= 0) {
      Class[] interfaces = scriptFactory.getScriptInterfaces();
View Full Code Here

    LifecycleMetadata metadata = findLifecycleMetadata(bean.getClass());
    try {
      metadata.invokeInitMethods(bean, beanName);
    }
    catch (InvocationTargetException ex) {
      throw new BeanCreationException(beanName, "Invocation of init method failed", ex.getTargetException());
    }
    catch (Throwable ex) {
      throw new BeanCreationException(beanName, "Couldn't invoke init method", ex);
    }
    return bean;
  }
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.