ParentName - The name of the parent definition of this bean definition.
BeanClassName - The bean class name of this bean definition. The class name can be modified during bean factory post-processing, typically replacing the original class name with a parsed variant of it.
Scope - Override the target scope of this bean, specifying a new scope name.
isLazyInit - Whether this bean should be lazily initialized.
DependsOn - The names of the beans that this bean depends on being initialized. The bean factory will guarantee that these beans get initialized first.
AutowireCandidate - Whether this bean is a candidate for getting autowired into some other bean.
Primary - Whether this bean is a primary autowire candidate.
FactoryBeanName - The factory bean to use. This the name of the bean to call the specified factory method on.
FactoryMethodName - Specify a factory method, if any. This method will be invoked with constructor arguments, or with no arguments if none are specified. The method will be invoked on the specified factory bean, if any, or otherwise as a static method on the local bean class.
ConstructorArgumentValues - Constructor argument values for this bean.
PropertyValues - The property values to be applied to a new instance of the bean.
InitMethodName - The name of the initializer method.
DestroyMethodName - The name of the destroy method.
Role - The role hint for this BeanDefinition. The role hint provides the frameworks as well as tools an indication of the role and importance of a particular BeanDefinition.
ResolvableType - A resolvable type for this bean definition, based on the bean class or other specific metadata.
isSingleton - Whether this a Singleton, with a single, shared instance returned on all calls.
isPrototype - Whether this a Prototype, with an independent instance returned for each call.
isAbstract - Whether this bean is "abstract", that is, not meant to be instantiated.
OriginatingBeanDefinition - The originating BeanDefinition.
AutowireMode - The autowire mode. This determines whether any automagical detection and setting of bean references will happen. Default is AUTOWIRE_NO which means there won't be convention-based autowiring by name or type (however, there may still be explicit annotation-driven autowiring).
public final MethodMetadata getFactoryMethodMetadata() {
return this.factoryMethodMetadata;
}
}
复制代码
Spring中使用BeanDefinition示例
注册componentClasses
AnnotationConfigApplicationContext启动代码:
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.register(ServiceConfig.class);
applicationContext.refresh();
复制代码
AnnotationConfigApplicationContext在启动时可以使用register方法注册@Configuration类,本小节将从这个方法入手看一个BeanDefinition的使用示例:
[code]public void register(Class... componentClasses) { Assert.notEmpty(componentClasses, "At least one component class must be specified"); this.reader.register(componentClasses);}// reader.register(...)public void register(Class... componentClasses) { for (Class componentClass : componentClasses) { registerBean(componentClass); }}private void doRegisterBean(Class beanClass, String name, Class