1 /* 2 * Copyright 2002-2012 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 import org.springframework.util.ClassUtils; 21 22 /** 23 * Exception thrown when a bean depends on other beans or simple properties 24 * that were not specified in the bean factory definition, although 25 * dependency checking was enabled. 26 * 27 * @author Rod Johnson 28 * @author Juergen Hoeller 29 * @since 03.09.2003 30 */ 31 @SuppressWarnings("serial") 32 public class UnsatisfiedDependencyException extends BeanCreationException { 33 34 /** 35 * Create a new UnsatisfiedDependencyException. 36 * @param resourceDescription description of the resource that the bean definition came from 37 * @param beanName the name of the bean requested 38 * @param propertyName the name of the bean property that couldn't be satisfied 39 * @param msg the detail message 40 */ 41 public UnsatisfiedDependencyException( 42 String resourceDescription, String beanName, String propertyName, String msg) { 43 44 super(resourceDescription, beanName, 45 "Unsatisfied dependency expressed through bean property '" + propertyName + "'" + 46 (msg != null ? ": " + msg : "")); 47 } 48 49 /** 50 * Create a new UnsatisfiedDependencyException. 51 * @param resourceDescription description of the resource that the bean definition came from 52 * @param beanName the name of the bean requested 53 * @param propertyName the name of the bean property that couldn't be satisfied 54 * @param ex the bean creation exception that indicated the unsatisfied dependency 55 */ 56 public UnsatisfiedDependencyException( 57 String resourceDescription, String beanName, String propertyName, BeansException ex) { 58 59 this(resourceDescription, beanName, propertyName, (ex != null ? ": " + ex.getMessage() : "")); 60 initCause(ex); 61 } 62 63 /** 64 * Create a new UnsatisfiedDependencyException. 65 * @param resourceDescription description of the resource that the bean definition came from 66 * @param beanName the name of the bean requested 67 * @param ctorArgIndex the index of the constructor argument that couldn't be satisfied 68 * @param ctorArgType the type of the constructor argument that couldn't be satisfied 69 * @param msg the detail message 70 */ 71 public UnsatisfiedDependencyException( 72 String resourceDescription, String beanName, int ctorArgIndex, Class<?> ctorArgType, String msg) { 73 74 super(resourceDescription, beanName, 75 "Unsatisfied dependency expressed through constructor argument with index " + 76 ctorArgIndex + " of type [" + ClassUtils.getQualifiedName(ctorArgType) + "]" + 77 (msg != null ? ": " + msg : "")); 78 } 79 80 /** 81 * Create a new UnsatisfiedDependencyException. 82 * @param resourceDescription description of the resource that the bean definition came from 83 * @param beanName the name of the bean requested 84 * @param ctorArgIndex the index of the constructor argument that couldn't be satisfied 85 * @param ctorArgType the type of the constructor argument that couldn't be satisfied 86 * @param ex the bean creation exception that indicated the unsatisfied dependency 87 */ 88 public UnsatisfiedDependencyException( 89 String resourceDescription, String beanName, int ctorArgIndex, Class<?> ctorArgType, BeansException ex) { 90 91 this(resourceDescription, beanName, ctorArgIndex, ctorArgType, (ex != null ? ": " + ex.getMessage() : "")); 92 initCause(ex); 93 } 94 95 }