001/* 002 * Copyright 2002-2017 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; 020 021/** 022 * Exception thrown when the BeanFactory cannot load the specified class 023 * of a given bean. 024 * 025 * @author Juergen Hoeller 026 * @since 2.0 027 */ 028@SuppressWarnings("serial") 029public class CannotLoadBeanClassException extends FatalBeanException { 030 031 private String resourceDescription; 032 033 private String beanName; 034 035 private String beanClassName; 036 037 038 /** 039 * Create a new CannotLoadBeanClassException. 040 * @param resourceDescription description of the resource 041 * that the bean definition came from 042 * @param beanName the name of the bean requested 043 * @param beanClassName the name of the bean class 044 * @param cause the root cause 045 */ 046 public CannotLoadBeanClassException( 047 String resourceDescription, String beanName, String beanClassName, ClassNotFoundException cause) { 048 049 super("Cannot find class [" + beanClassName + "] for bean with name '" + beanName + "'" + 050 (resourceDescription != null ? " defined in " + resourceDescription : ""), cause); 051 this.resourceDescription = resourceDescription; 052 this.beanName = beanName; 053 this.beanClassName = beanClassName; 054 } 055 056 /** 057 * Create a new CannotLoadBeanClassException. 058 * @param resourceDescription description of the resource 059 * that the bean definition came from 060 * @param beanName the name of the bean requested 061 * @param beanClassName the name of the bean class 062 * @param cause the root cause 063 */ 064 public CannotLoadBeanClassException( 065 String resourceDescription, String beanName, String beanClassName, LinkageError cause) { 066 067 super("Error loading class [" + beanClassName + "] for bean with name '" + beanName + "'" + 068 (resourceDescription != null ? " defined in " + resourceDescription : "") + 069 ": problem with class file or dependent class", cause); 070 this.resourceDescription = resourceDescription; 071 this.beanName = beanName; 072 this.beanClassName = beanClassName; 073 } 074 075 076 /** 077 * Return the description of the resource that the bean 078 * definition came from. 079 */ 080 public String getResourceDescription() { 081 return this.resourceDescription; 082 } 083 084 /** 085 * Return the name of the bean requested. 086 */ 087 public String getBeanName() { 088 return this.beanName; 089 } 090 091 /** 092 * Return the name of the class we were trying to load. 093 */ 094 public String getBeanClassName() { 095 return this.beanClassName; 096 } 097 098}