1 /* 2 * Copyright 2002-2005 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 /** 20 * Interface to be implemented by beans that want to release resources 21 * on destruction. A BeanFactory is supposed to invoke the destroy 22 * method if it disposes a cached singleton. An application context 23 * is supposed to dispose all of its singletons on close. 24 * 25 * <p>An alternative to implementing DisposableBean is specifying a custom 26 * destroy-method, for example in an XML bean definition. 27 * For a list of all bean lifecycle methods, see the BeanFactory javadocs. 28 * 29 * @author Juergen Hoeller 30 * @since 12.08.2003 31 * @see org.springframework.beans.factory.support.RootBeanDefinition#getDestroyMethodName 32 * @see org.springframework.context.ConfigurableApplicationContext#close 33 */ 34 public interface DisposableBean { 35 36 /** 37 * Invoked by a BeanFactory on destruction of a singleton. 38 * @throws Exception in case of shutdown errors. 39 * Exceptions will get logged but not rethrown to allow 40 * other beans to release their resources too. 41 */ 42 void destroy() throws Exception; 43 44 } 45