001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.beans.factory; 018 019import org.springframework.beans.FatalBeanException; 020import org.springframework.lang.Nullable; 021 022/** 023 * Exception thrown when a BeanFactory encounters an invalid bean definition: 024 * e.g. in case of incomplete or contradictory bean metadata. 025 * 026 * @author Rod Johnson 027 * @author Juergen Hoeller 028 * @author Rob Harrop 029 */ 030@SuppressWarnings("serial") 031public class BeanDefinitionStoreException extends FatalBeanException { 032 033 @Nullable 034 private final String resourceDescription; 035 036 @Nullable 037 private final String beanName; 038 039 040 /** 041 * Create a new BeanDefinitionStoreException. 042 * @param msg the detail message (used as exception message as-is) 043 */ 044 public BeanDefinitionStoreException(String msg) { 045 super(msg); 046 this.resourceDescription = null; 047 this.beanName = null; 048 } 049 050 /** 051 * Create a new BeanDefinitionStoreException. 052 * @param msg the detail message (used as exception message as-is) 053 * @param cause the root cause (may be {@code null}) 054 */ 055 public BeanDefinitionStoreException(String msg, @Nullable Throwable cause) { 056 super(msg, cause); 057 this.resourceDescription = null; 058 this.beanName = null; 059 } 060 061 /** 062 * Create a new BeanDefinitionStoreException. 063 * @param resourceDescription description of the resource that the bean definition came from 064 * @param msg the detail message (used as exception message as-is) 065 */ 066 public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg) { 067 super(msg); 068 this.resourceDescription = resourceDescription; 069 this.beanName = null; 070 } 071 072 /** 073 * Create a new BeanDefinitionStoreException. 074 * @param resourceDescription description of the resource that the bean definition came from 075 * @param msg the detail message (used as exception message as-is) 076 * @param cause the root cause (may be {@code null}) 077 */ 078 public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg, @Nullable Throwable cause) { 079 super(msg, cause); 080 this.resourceDescription = resourceDescription; 081 this.beanName = null; 082 } 083 084 /** 085 * Create a new BeanDefinitionStoreException. 086 * @param resourceDescription description of the resource that the bean definition came from 087 * @param beanName the name of the bean 088 * @param msg the detail message (appended to an introductory message that indicates 089 * the resource and the name of the bean) 090 */ 091 public BeanDefinitionStoreException(@Nullable String resourceDescription, String beanName, String msg) { 092 this(resourceDescription, beanName, msg, null); 093 } 094 095 /** 096 * Create a new BeanDefinitionStoreException. 097 * @param resourceDescription description of the resource that the bean definition came from 098 * @param beanName the name of the bean 099 * @param msg the detail message (appended to an introductory message that indicates 100 * the resource and the name of the bean) 101 * @param cause the root cause (may be {@code null}) 102 */ 103 public BeanDefinitionStoreException( 104 @Nullable String resourceDescription, String beanName, String msg, @Nullable Throwable cause) { 105 106 super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg, 107 cause); 108 this.resourceDescription = resourceDescription; 109 this.beanName = beanName; 110 } 111 112 113 /** 114 * Return the description of the resource that the bean definition came from, if available. 115 */ 116 @Nullable 117 public String getResourceDescription() { 118 return this.resourceDescription; 119 } 120 121 /** 122 * Return the name of the bean, if available. 123 */ 124 @Nullable 125 public String getBeanName() { 126 return this.beanName; 127 } 128 129}