1 /* 2 * Copyright 2002-2014 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.config; 18 19 import java.util.Iterator; 20 21 import org.springframework.beans.BeansException; 22 import org.springframework.beans.factory.ListableBeanFactory; 23 import org.springframework.beans.factory.NoSuchBeanDefinitionException; 24 25 /** 26 * Configuration interface to be implemented by most listable bean factories. 27 * In addition to {@link ConfigurableBeanFactory}, it provides facilities to 28 * analyze and modify bean definitions, and to pre-instantiate singletons. 29 * 30 * <p>This subinterface of {@link org.springframework.beans.factory.BeanFactory} 31 * is not meant to be used in normal application code: Stick to 32 * {@link org.springframework.beans.factory.BeanFactory} or 33 * {@link org.springframework.beans.factory.ListableBeanFactory} for typical 34 * use cases. This interface is just meant to allow for framework-internal 35 * plug'n'play even when needing access to bean factory configuration methods. 36 * 37 * @author Juergen Hoeller 38 * @since 03.11.2003 39 * @see org.springframework.context.support.AbstractApplicationContext#getBeanFactory() 40 */ 41 public interface ConfigurableListableBeanFactory 42 extends ListableBeanFactory, AutowireCapableBeanFactory, ConfigurableBeanFactory { 43 44 /** 45 * Ignore the given dependency type for autowiring: 46 * for example, String. Default is none. 47 * @param type the dependency type to ignore 48 */ 49 void ignoreDependencyType(Class<?> type); 50 51 /** 52 * Ignore the given dependency interface for autowiring. 53 * <p>This will typically be used by application contexts to register 54 * dependencies that are resolved in other ways, like BeanFactory through 55 * BeanFactoryAware or ApplicationContext through ApplicationContextAware. 56 * <p>By default, only the BeanFactoryAware interface is ignored. 57 * For further types to ignore, invoke this method for each type. 58 * @param ifc the dependency interface to ignore 59 * @see org.springframework.beans.factory.BeanFactoryAware 60 * @see org.springframework.context.ApplicationContextAware 61 */ 62 void ignoreDependencyInterface(Class<?> ifc); 63 64 /** 65 * Register a special dependency type with corresponding autowired value. 66 * <p>This is intended for factory/context references that are supposed 67 * to be autowirable but are not defined as beans in the factory: 68 * e.g. a dependency of type ApplicationContext resolved to the 69 * ApplicationContext instance that the bean is living in. 70 * <p>Note: There are no such default types registered in a plain BeanFactory, 71 * not even for the BeanFactory interface itself. 72 * @param dependencyType the dependency type to register. This will typically 73 * be a base interface such as BeanFactory, with extensions of it resolved 74 * as well if declared as an autowiring dependency (e.g. ListableBeanFactory), 75 * as long as the given value actually implements the extended interface. 76 * @param autowiredValue the corresponding autowired value. This may also be an 77 * implementation of the {@link org.springframework.beans.factory.ObjectFactory} 78 * interface, which allows for lazy resolution of the actual target value. 79 */ 80 void registerResolvableDependency(Class<?> dependencyType, Object autowiredValue); 81 82 /** 83 * Determine whether the specified bean qualifies as an autowire candidate, 84 * to be injected into other beans which declare a dependency of matching type. 85 * <p>This method checks ancestor factories as well. 86 * @param beanName the name of the bean to check 87 * @param descriptor the descriptor of the dependency to resolve 88 * @return whether the bean should be considered as autowire candidate 89 * @throws NoSuchBeanDefinitionException if there is no bean with the given name 90 */ 91 boolean isAutowireCandidate(String beanName, DependencyDescriptor descriptor) 92 throws NoSuchBeanDefinitionException; 93 94 /** 95 * Return the registered BeanDefinition for the specified bean, allowing access 96 * to its property values and constructor argument value (which can be 97 * modified during bean factory post-processing). 98 * <p>A returned BeanDefinition object should not be a copy but the original 99 * definition object as registered in the factory. This means that it should 100 * be castable to a more specific implementation type, if necessary. 101 * <p><b>NOTE:</b> This method does <i>not</i> consider ancestor factories. 102 * It is only meant for accessing local bean definitions of this factory. 103 * @param beanName the name of the bean 104 * @return the registered BeanDefinition 105 * @throws NoSuchBeanDefinitionException if there is no bean with the given name 106 * defined in this factory 107 */ 108 BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException; 109 110 /** 111 * Return a unified view over all bean names managed by this factory. 112 * <p>Includes bean definition names as well as names of manually registered 113 * singleton instances, with bean definition names consistently coming first, 114 * analogous to how type/annotation specific retrieval of bean names works. 115 * @return the composite iterator for the bean names view 116 * @since 4.1.2 117 * @see #containsBeanDefinition 118 * @see #registerSingleton 119 * @see #getBeanNamesForType 120 * @see #getBeanNamesForAnnotation 121 */ 122 Iterator<String> getBeanNamesIterator(); 123 124 /** 125 * Freeze all bean definitions, signalling that the registered bean definitions 126 * will not be modified or post-processed any further. 127 * <p>This allows the factory to aggressively cache bean definition metadata. 128 */ 129 void freezeConfiguration(); 130 131 /** 132 * Return whether this factory's bean definitions are frozen, 133 * i.e. are not supposed to be modified or post-processed any further. 134 * @return {@code true} if the factory's configuration is considered frozen 135 */ 136 boolean isConfigurationFrozen(); 137 138 /** 139 * Ensure that all non-lazy-init singletons are instantiated, also considering 140 * {@link org.springframework.beans.factory.FactoryBean FactoryBeans}. 141 * Typically invoked at the end of factory setup, if desired. 142 * @throws BeansException if one of the singleton beans could not be created. 143 * Note: This may have left the factory with some beans already initialized! 144 * Call {@link #destroySingletons()} for full cleanup in this case. 145 * @see #destroySingletons() 146 */ 147 void preInstantiateSingletons() throws BeansException; 148 149 }