Home » Spring-Framework-090522 » org.springframework » beans » factory » [javadoc | source]

    1   /*
    2    * Copyright 2002-2007 the original author or authors.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
   10    * Unless required by applicable law or agreed to in writing, software
   11    * distributed under the License is distributed on an "AS IS" BASIS,
   12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13    * See the License for the specific language governing permissions and
   14    * limitations under the License.
   15    */
   16   
   17   package org.springframework.beans.factory;
   18   
   19   import org.springframework.beans.BeansException;
   20   
   21   /**
   22    * Exception thrown when a BeanFactory is asked for a bean
   23    * instance name for which it cannot find a definition.
   24    *
   25    * @author Rod Johnson
   26    * @author Juergen Hoeller
   27    */
   28   public class NoSuchBeanDefinitionException extends BeansException {
   29   
   30   	/** Name of the missing bean */
   31   	private String beanName;
   32   
   33   	/** Required bean type */
   34   	private Class beanType;
   35   
   36   
   37   	/**
   38   	 * Create a new NoSuchBeanDefinitionException.
   39   	 * @param name the name of the missing bean
   40   	 */
   41   	public NoSuchBeanDefinitionException(String name) {
   42   		super("No bean named '" + name + "' is defined");
   43   		this.beanName = name;
   44   	}
   45   
   46   	/**
   47   	 * Create a new NoSuchBeanDefinitionException.
   48   	 * @param name the name of the missing bean
   49   	 * @param message detailed message describing the problem
   50   	 */
   51   	public NoSuchBeanDefinitionException(String name, String message) {
   52   		super("No bean named '" + name + "' is defined: " + message);
   53   		this.beanName = name;
   54   	}
   55   
   56   	/**
   57   	 * Create a new NoSuchBeanDefinitionException.
   58   	 * @param type required type of bean
   59   	 * @param message detailed message describing the problem
   60   	 */
   61   	public NoSuchBeanDefinitionException(Class type, String message) {
   62   		super("No unique bean of type [" + type.getName() + "] is defined: " + message);
   63   		this.beanType = type;
   64   	}
   65   
   66   	/**
   67   	 * Create a new NoSuchBeanDefinitionException.
   68   	 * @param type required type of bean
   69   	 * @param dependencyDescription a description of the originating dependency
   70   	 * @param message detailed message describing the problem
   71   	 */
   72   	public NoSuchBeanDefinitionException(Class type, String dependencyDescription, String message) {
   73   		super("No matching bean of type [" + type.getName() + "] found for dependency [" +
   74   				dependencyDescription + "]: " + message);
   75   		this.beanType = type;
   76   	}
   77   
   78   
   79   	/**
   80   	 * Return the name of the missing bean,
   81   	 * if it was a lookup by name that failed.
   82   	 */
   83   	public String getBeanName() {
   84   		return this.beanName;
   85   	}
   86   
   87   	/**
   88   	 * Return the required type of bean,
   89   	 * if it was a lookup by type that failed.
   90   	 */
   91   	public Class getBeanType() {
   92   		return this.beanType;
   93   	}
   94   
   95   }

Home » Spring-Framework-090522 » org.springframework » beans » factory » [javadoc | source]