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 org.springframework.beans.BeanMetadataElement; 20 import org.springframework.beans.MutablePropertyValues; 21 import org.springframework.core.AttributeAccessor; 22 23 /** 24 * A BeanDefinition describes a bean instance, which has property values, 25 * constructor argument values, and further information supplied by 26 * concrete implementations. 27 * 28 * <p>This is just a minimal interface: The main intention is to allow a 29 * {@link BeanFactoryPostProcessor} such as {@link PropertyPlaceholderConfigurer} 30 * to introspect and modify property values and other bean metadata. 31 * 32 * @author Juergen Hoeller 33 * @author Rob Harrop 34 * @since 19.03.2004 35 * @see ConfigurableListableBeanFactory#getBeanDefinition 36 * @see org.springframework.beans.factory.support.RootBeanDefinition 37 * @see org.springframework.beans.factory.support.ChildBeanDefinition 38 */ 39 public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { 40 41 /** 42 * Scope identifier for the standard singleton scope: "singleton". 43 * <p>Note that extended bean factories might support further scopes. 44 * @see #setScope 45 */ 46 String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON; 47 48 /** 49 * Scope identifier for the standard prototype scope: "prototype". 50 * <p>Note that extended bean factories might support further scopes. 51 * @see #setScope 52 */ 53 String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE; 54 55 56 /** 57 * Role hint indicating that a {@code BeanDefinition} is a major part 58 * of the application. Typically corresponds to a user-defined bean. 59 */ 60 int ROLE_APPLICATION = 0; 61 62 /** 63 * Role hint indicating that a {@code BeanDefinition} is a supporting 64 * part of some larger configuration, typically an outer 65 * {@link org.springframework.beans.factory.parsing.ComponentDefinition}. 66 * {@code SUPPORT} beans are considered important enough to be aware 67 * of when looking more closely at a particular 68 * {@link org.springframework.beans.factory.parsing.ComponentDefinition}, 69 * but not when looking at the overall configuration of an application. 70 */ 71 int ROLE_SUPPORT = 1; 72 73 /** 74 * Role hint indicating that a {@code BeanDefinition} is providing an 75 * entirely background role and has no relevance to the end-user. This hint is 76 * used when registering beans that are completely part of the internal workings 77 * of a {@link org.springframework.beans.factory.parsing.ComponentDefinition}. 78 */ 79 int ROLE_INFRASTRUCTURE = 2; 80 81 82 /** 83 * Return the name of the parent definition of this bean definition, if any. 84 */ 85 String getParentName(); 86 87 /** 88 * Set the name of the parent definition of this bean definition, if any. 89 */ 90 void setParentName(String parentName); 91 92 /** 93 * Return the current bean class name of this bean definition. 94 * <p>Note that this does not have to be the actual class name used at runtime, in 95 * case of a child definition overriding/inheriting the class name from its parent. 96 * Hence, do <i>not</i> consider this to be the definitive bean type at runtime but 97 * rather only use it for parsing purposes at the individual bean definition level. 98 */ 99 String getBeanClassName(); 100 101 /** 102 * Override the bean class name of this bean definition. 103 * <p>The class name can be modified during bean factory post-processing, 104 * typically replacing the original class name with a parsed variant of it. 105 */ 106 void setBeanClassName(String beanClassName); 107 108 /** 109 * Return the factory bean name, if any. 110 */ 111 String getFactoryBeanName(); 112 113 /** 114 * Specify the factory bean to use, if any. 115 */ 116 void setFactoryBeanName(String factoryBeanName); 117 118 /** 119 * Return a factory method, if any. 120 */ 121 String getFactoryMethodName(); 122 123 /** 124 * Specify a factory method, if any. This method will be invoked with 125 * constructor arguments, or with no arguments if none are specified. 126 * The method will be invoked on the specified factory bean, if any, 127 * or otherwise as a static method on the local bean class. 128 * @param factoryMethodName static factory method name, 129 * or {@code null} if normal constructor creation should be used 130 * @see #getBeanClassName() 131 */ 132 void setFactoryMethodName(String factoryMethodName); 133 134 /** 135 * Return the name of the current target scope for this bean, 136 * or {@code null} if not known yet. 137 */ 138 String getScope(); 139 140 /** 141 * Override the target scope of this bean, specifying a new scope name. 142 * @see #SCOPE_SINGLETON 143 * @see #SCOPE_PROTOTYPE 144 */ 145 void setScope(String scope); 146 147 /** 148 * Return whether this bean should be lazily initialized, i.e. not 149 * eagerly instantiated on startup. Only applicable to a singleton bean. 150 */ 151 boolean isLazyInit(); 152 153 /** 154 * Set whether this bean should be lazily initialized. 155 * <p>If {@code false}, the bean will get instantiated on startup by bean 156 * factories that perform eager initialization of singletons. 157 */ 158 void setLazyInit(boolean lazyInit); 159 160 /** 161 * Return the bean names that this bean depends on. 162 */ 163 String[] getDependsOn(); 164 165 /** 166 * Set the names of the beans that this bean depends on being initialized. 167 * The bean factory will guarantee that these beans get initialized first. 168 */ 169 void setDependsOn(String... dependsOn); 170 171 /** 172 * Return whether this bean is a candidate for getting autowired into some other bean. 173 */ 174 boolean isAutowireCandidate(); 175 176 /** 177 * Set whether this bean is a candidate for getting autowired into some other bean. 178 */ 179 void setAutowireCandidate(boolean autowireCandidate); 180 181 /** 182 * Return whether this bean is a primary autowire candidate. 183 * If this value is true for exactly one bean among multiple 184 * matching candidates, it will serve as a tie-breaker. 185 */ 186 boolean isPrimary(); 187 188 /** 189 * Set whether this bean is a primary autowire candidate. 190 * <p>If this value is true for exactly one bean among multiple 191 * matching candidates, it will serve as a tie-breaker. 192 */ 193 void setPrimary(boolean primary); 194 195 196 /** 197 * Return the constructor argument values for this bean. 198 * <p>The returned instance can be modified during bean factory post-processing. 199 * @return the ConstructorArgumentValues object (never {@code null}) 200 */ 201 ConstructorArgumentValues getConstructorArgumentValues(); 202 203 /** 204 * Return the property values to be applied to a new instance of the bean. 205 * <p>The returned instance can be modified during bean factory post-processing. 206 * @return the MutablePropertyValues object (never {@code null}) 207 */ 208 MutablePropertyValues getPropertyValues(); 209 210 211 /** 212 * Return whether this a <b>Singleton</b>, with a single, shared instance 213 * returned on all calls. 214 * @see #SCOPE_SINGLETON 215 */ 216 boolean isSingleton(); 217 218 /** 219 * Return whether this a <b>Prototype</b>, with an independent instance 220 * returned for each call. 221 * @see #SCOPE_PROTOTYPE 222 */ 223 boolean isPrototype(); 224 225 /** 226 * Return whether this bean is "abstract", that is, not meant to be instantiated. 227 */ 228 boolean isAbstract(); 229 230 /** 231 * Get the role hint for this {@code BeanDefinition}. The role hint 232 * provides the frameworks as well as tools with an indication of 233 * the role and importance of a particular {@code BeanDefinition}. 234 * @see #ROLE_APPLICATION 235 * @see #ROLE_SUPPORT 236 * @see #ROLE_INFRASTRUCTURE 237 */ 238 int getRole(); 239 240 /** 241 * Return a human-readable description of this bean definition. 242 */ 243 String getDescription(); 244 245 /** 246 * Return a description of the resource that this bean definition 247 * came from (for the purpose of showing context in case of errors). 248 */ 249 String getResourceDescription(); 250 251 /** 252 * Return the originating BeanDefinition, or {@code null} if none. 253 * Allows for retrieving the decorated bean definition, if any. 254 * <p>Note that this method returns the immediate originator. Iterate through the 255 * originator chain to find the original BeanDefinition as defined by the user. 256 */ 257 BeanDefinition getOriginatingBeanDefinition(); 258 259 }