001/*
002 * Copyright 2002-2011 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
019/**
020 * Interface to be implemented by beans that want to be aware of their
021 * bean name in a bean factory. Note that it is not usually recommended
022 * that an object depend on its bean name, as this represents a potentially
023 * brittle dependence on external configuration, as well as a possibly
024 * unnecessary dependence on a Spring API.
025 *
026 * <p>For a list of all bean lifecycle methods, see the
027 * {@link BeanFactory BeanFactory javadocs}.
028 *
029 * @author Juergen Hoeller
030 * @author Chris Beams
031 * @since 01.11.2003
032 * @see BeanClassLoaderAware
033 * @see BeanFactoryAware
034 * @see InitializingBean
035 */
036public interface BeanNameAware extends Aware {
037
038        /**
039         * Set the name of the bean in the bean factory that created this bean.
040         * <p>Invoked after population of normal bean properties but before an
041         * init callback such as {@link InitializingBean#afterPropertiesSet()}
042         * or a custom init-method.
043         * @param name the name of the bean in the factory.
044         * Note that this name is the actual bean name used in the factory, which may
045         * differ from the originally specified name: in particular for inner bean
046         * names, the actual bean name might have been made unique through appending
047         * "#..." suffixes. Use the {@link BeanFactoryUtils#originalBeanName(String)}
048         * method to extract the original bean name (without suffix), if desired.
049         */
050        void setBeanName(String name);
051
052}