01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: * Create a new NoSuchBeanDefinitionException.
38: * @param name the name of the missing bean
39: */
40: public NoSuchBeanDefinitionException(String name) {
41: super ("No bean named '" + name + "' is defined");
42: this .beanName = name;
43: }
44:
45: /**
46: * Create a new NoSuchBeanDefinitionException.
47: * @param name the name of the missing bean
48: * @param message further, detailed message describing the problem
49: */
50: public NoSuchBeanDefinitionException(String name, String message) {
51: super ("No bean named '" + name + "' is defined: " + message);
52: this .beanName = name;
53: }
54:
55: /**
56: * Create a new NoSuchBeanDefinitionException.
57: * @param type required type of bean
58: * @param message further, detailed message describing the problem
59: */
60: public NoSuchBeanDefinitionException(Class type, String message) {
61: super ("No unique bean of type [" + type.getName()
62: + "] is defined: " + message);
63: this .beanType = type;
64: }
65:
66: /**
67: * Return the name of the missing bean,
68: * if it was a lookup by name that failed.
69: */
70: public String getBeanName() {
71: return this .beanName;
72: }
73:
74: /**
75: * Return the required type of bean,
76: * if it was a lookup by type that failed.
77: */
78: public Class getBeanType() {
79: return this.beanType;
80: }
81:
82: }
|