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.FatalBeanException; 20 21 /** 22 * Exception thrown when a BeanFactory encounters an invalid bean definition: 23 * e.g. in case of incomplete or contradictory bean metadata. 24 * 25 * @author Rod Johnson 26 * @author Juergen Hoeller 27 * @author Rob Harrop 28 */ 29 @SuppressWarnings("serial") 30 public class BeanDefinitionStoreException extends FatalBeanException { 31 32 private String resourceDescription; 33 34 private String beanName; 35 36 37 /** 38 * Create a new BeanDefinitionStoreException. 39 * @param msg the detail message (used as exception message as-is) 40 */ 41 public BeanDefinitionStoreException(String msg) { 42 super(msg); 43 } 44 45 /** 46 * Create a new BeanDefinitionStoreException. 47 * @param msg the detail message (used as exception message as-is) 48 * @param cause the root cause (may be {@code null}) 49 */ 50 public BeanDefinitionStoreException(String msg, Throwable cause) { 51 super(msg, cause); 52 } 53 54 /** 55 * Create a new BeanDefinitionStoreException. 56 * @param resourceDescription description of the resource that the bean definition came from 57 * @param msg the detail message (used as exception message as-is) 58 */ 59 public BeanDefinitionStoreException(String resourceDescription, String msg) { 60 super(msg); 61 this.resourceDescription = resourceDescription; 62 } 63 64 /** 65 * Create a new BeanDefinitionStoreException. 66 * @param resourceDescription description of the resource that the bean definition came from 67 * @param msg the detail message (used as exception message as-is) 68 * @param cause the root cause (may be {@code null}) 69 */ 70 public BeanDefinitionStoreException(String resourceDescription, String msg, Throwable cause) { 71 super(msg, cause); 72 this.resourceDescription = resourceDescription; 73 } 74 75 /** 76 * Create a new BeanDefinitionStoreException. 77 * @param resourceDescription description of the resource that the bean definition came from 78 * @param beanName the name of the bean requested 79 * @param msg the detail message (appended to an introductory message that indicates 80 * the resource and the name of the bean) 81 */ 82 public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg) { 83 this(resourceDescription, beanName, msg, null); 84 } 85 86 /** 87 * Create a new BeanDefinitionStoreException. 88 * @param resourceDescription description of the resource that the bean definition came from 89 * @param beanName the name of the bean requested 90 * @param msg the detail message (appended to an introductory message that indicates 91 * the resource and the name of the bean) 92 * @param cause the root cause (may be {@code null}) 93 */ 94 public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg, Throwable cause) { 95 super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg, cause); 96 this.resourceDescription = resourceDescription; 97 this.beanName = beanName; 98 } 99 100 101 /** 102 * Return the description of the resource that the bean 103 * definition came from, if any. 104 */ 105 public String getResourceDescription() { 106 return this.resourceDescription; 107 } 108 109 /** 110 * Return the name of the bean requested, if any. 111 */ 112 public String getBeanName() { 113 return this.beanName; 114 } 115 116 }