ConfigurableBeanFactory
ConfigurableBeanFactory :关系如下
在上面这样的一个关系图中可以先看下SingletonBeanRegistry的源代码:
package org.springframework.beans.factory.config;
public interface SingletonBeanRegistry {
//在容器中创建一个指定的单利bean的类
void registerSingleton(String beanName, Object singletonObject);
//返回一个单利类
Object getSingleton(String beanName);
//判断容器红是否错在这个单例的bean
boolean containsSingleton(String beanName);
//返回这个单例bean的所有名字
String[] getSingletonNames();
//统计单例Bean的个数
int getSingletonCount();
Object getSingletonMutex();
}
这个接口的方法:主要单例bean的注册,生成实例,以及统计单例bean
ConfigurableBeanFactory :源代码
/*
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ package org.springframework.beans.factory.config; import java.beans.PropertyEditor;
import java.security.AccessControlContext; import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.TypeConverter;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.core.convert.ConversionService;
import org.springframework.util.StringValueResolver; /**
* Configuration interface to be implemented by most bean factories. Provides
* facilities to configure a bean factory, in addition to the bean factory
* client methods in the {@link org.springframework.beans.factory.BeanFactory}
* interface.
*
* <p>This bean factory interface is not meant to be used in normal application
* code: Stick to {@link org.springframework.beans.factory.BeanFactory} or
* {@link org.springframework.beans.factory.ListableBeanFactory} for typical
* needs. This extended interface is just meant to allow for framework-internal
* plug'n'play and for special access to bean factory configuration methods.
*
* @author Juergen Hoeller
* @since 03.11.2003
* @see org.springframework.beans.factory.BeanFactory
* @see org.springframework.beans.factory.ListableBeanFactory
* @see ConfigurableListableBeanFactory
*/
public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, SingletonBeanRegistry { /**
* Scope identifier for the standard singleton scope: "singleton".
* Custom scopes can be added via {@code registerScope}.
* @see #registerScope
*/ String SCOPE_SINGLETON = "singleton"; /**
* Scope identifier for the standard prototype scope: "prototype".
* Custom scopes can be added via {@code registerScope}.
* @see #registerScope
*/
String SCOPE_PROTOTYPE = "prototype"; /**
* Set the parent of this bean factory.
* <p>Note that the parent cannot be changed: It should only be set outside
* a constructor if it isn't available at the time of factory instantiation.
* @param parentBeanFactory the parent BeanFactory
* @throws IllegalStateException if this factory is already associated with
* a parent BeanFactory
* @see #getParentBeanFactory()
*/
//搭配父接口HierarchicalBeanFactory 中得getParentBeanFactory()
void setParentBeanFactory(BeanFactory parentBeanFactory) throws IllegalStateException; /**
* Set the class loader to use for loading bean classes.
* Default is the thread context class loader.
* <p>Note that this class loader will only apply to bean definitions
* that do not carry a resolved bean class yet. This is the case as of
* Spring 2.0 by default: Bean definitions only carry bean class names,
* to be resolved once the factory processes the bean definition.
* @param beanClassLoader the class loader to use,
* or {@code null} to suggest the default class loader
*/
//设置bean的类加载器
void setBeanClassLoader(ClassLoader beanClassLoader); /**
* Return this factory's class loader for loading bean classes.
*/
//返回类的加载器
ClassLoader getBeanClassLoader(); /**
* Specify a temporary ClassLoader to use for type matching purposes.
* Default is none, simply using the standard bean ClassLoader.
* <p>A temporary ClassLoader is usually just specified if
* <i>load-time weaving</i> is involved, to make sure that actual bean
* classes are loaded as lazily as possible. The temporary loader is
* then removed once the BeanFactory completes its bootstrap phase.
* @since 2.5
*/
//设置一个零时的类加载器
void setTempClassLoader(ClassLoader tempClassLoader); /**
* Return the temporary ClassLoader to use for type matching purposes,
* if any.
* @since 2.5
*/
//返回一个零时的类加载器
ClassLoader getTempClassLoader(); /**
* Set whether to cache bean metadata such as given bean definitions
* (in merged fashion) and resolved bean classes. Default is on.
* <p>Turn this flag off to enable hot-refreshing of bean definition objects
* and in particular bean classes. If this flag is off, any creation of a bean
* instance will re-query the bean class loader for newly resolved classes.
*/
//设置是否缓存源,false石化,从新从类加载器加载
void setCacheBeanMetadata(boolean cacheBeanMetadata); /**
* Return whether to cache bean metadata such as given bean definitions
* (in merged fashion) and resolved bean classes.
*/
//是否缓存了definitions
boolean isCacheBeanMetadata(); /**
* Specify the resolution strategy for expressions in bean definition values.
* <p>There is no expression support active in a BeanFactory by default.
* An ApplicationContext will typically set a standard expression strategy
* here, supporting "#{...}" expressions in a Unified EL compatible style.
* @since 3.0
*/
//bean的表达式解析
void setBeanExpressionResolver(BeanExpressionResolver resolver); /**
* Return the resolution strategy for expressions in bean definition values.
* @since 3.0
*/
//获取bean的表达式解析
BeanExpressionResolver getBeanExpressionResolver(); /**
* Specify a Spring 3.0 ConversionService to use for converting
* property values, as an alternative to JavaBeans PropertyEditors.
* @since 3.0
*/
//设置一个转换服务
void setConversionService(ConversionService conversionService); /**
* Return the associated ConversionService, if any.
* @since 3.0
*/
//返回一个转换服务
ConversionService getConversionService(); /**
* Add a PropertyEditorRegistrar to be applied to all bean creation processes.
* <p>Such a registrar creates new PropertyEditor instances and registers them
* on the given registry, fresh for each bean creation attempt. This avoids
* the need for synchronization on custom editors; hence, it is generally
* preferable to use this method instead of {@link #registerCustomEditor}.
* @param registrar the PropertyEditorRegistrar to register
*/
//设置属性注册员
void addPropertyEditorRegistrar(PropertyEditorRegistrar registrar); /**
* Register the given custom property editor for all properties of the
* given type. To be invoked during factory configuration.
* <p>Note that this method will register a shared custom editor instance;
* access to that instance will be synchronized for thread-safety. It is
* generally preferable to use {@link #addPropertyEditorRegistrar} instead
* of this method, to avoid for the need for synchronization on custom editors.
* @param requiredType type of the property
* @param propertyEditorClass the {@link PropertyEditor} class to register
*/
//注册属性编辑器
void registerCustomEditor(Class<?> requiredType, Class<? extends PropertyEditor> propertyEditorClass); /**
* Initialize the given PropertyEditorRegistry with the custom editors
* that have been registered with this BeanFactory.
* @param registry the PropertyEditorRegistry to initialize
*/
//复制属性编辑器
void copyRegisteredEditorsTo(PropertyEditorRegistry registry); /**
* Set a custom type converter that this BeanFactory should use for converting
* bean property values, constructor argument values, etc.
* <p>This will override the default PropertyEditor mechanism and hence make
* any custom editors or custom editor registrars irrelevant.
* @see #addPropertyEditorRegistrar
* @see #registerCustomEditor
* @since 2.5
*/
//设置类型转换器
void setTypeConverter(TypeConverter typeConverter); /**
* Obtain a type converter as used by this BeanFactory. This may be a fresh
* instance for each call, since TypeConverters are usually <i>not</i> thread-safe.
* <p>If the default PropertyEditor mechanism is active, the returned
* TypeConverter will be aware of all custom editors that have been registered.
* @since 2.5
*/
//获取类型转换器
TypeConverter getTypeConverter(); /**
* Add a String resolver for embedded values such as annotation attributes.
* @param valueResolver the String resolver to apply to embedded values
* @since 3.0
*/
// 增加一个嵌入式的StringValueResolver
void addEmbeddedValueResolver(StringValueResolver valueResolver); /**
* Determine whether an embedded value resolver has been registered with this
* bean factory, to be applied through {@link #resolveEmbeddedValue(String)}.
* @since 4.3
*/ boolean hasEmbeddedValueResolver(); /**
* Resolve the given embedded value, e.g. an annotation attribute.
* @param value the value to resolve
* @return the resolved value (may be the original value as-is)
* @since 3.0
*/
//分解指定的嵌入式的值
String resolveEmbeddedValue(String value); /**
* Add a new BeanPostProcessor that will get applied to beans created
* by this factory. To be invoked during factory configuration.
* <p>Note: Post-processors submitted here will be applied in the order of
* registration; any ordering semantics expressed through implementing the
* {@link org.springframework.core.Ordered} interface will be ignored. Note
* that autodetected post-processors (e.g. as beans in an ApplicationContext)
* will always be applied after programmatically registered ones.
* @param beanPostProcessor the post-processor to register
*/
//增加一个BeanPostProcessor的处理器 前后
void addBeanPostProcessor(BeanPostProcessor beanPostProcessor); /**
* Return the current number of registered BeanPostProcessors, if any.
*/
int getBeanPostProcessorCount(); /**
* Register the given scope, backed by the given Scope implementation.
* @param scopeName the scope identifier
* @param scope the backing Scope implementation
*/
//注册bean的范围
void registerScope(String scopeName, Scope scope); /**
* Return the names of all currently registered scopes.
* <p>This will only return the names of explicitly registered scopes.
* Built-in scopes such as "singleton" and "prototype" won't be exposed.
* @return the array of scope names, or an empty array if none
* @see #registerScope
*/
//获取Bean的范围
String[] getRegisteredScopeNames(); /**
* Return the Scope implementation for the given scope name, if any.
* <p>This will only return explicitly registered scopes.
* Built-in scopes such as "singleton" and "prototype" won't be exposed.
* @param scopeName the name of the scope
* @return the registered Scope implementation, or {@code null} if none
* @see #registerScope
*/
//获取注册的范围
Scope getRegisteredScope(String scopeName); /**
* Provides a security access control context relevant to this factory.
* @return the applicable AccessControlContext (never {@code null})
* @since 3.0
*/
//返回本工厂的一个安全访问上下文
AccessControlContext getAccessControlContext(); /**
* Copy all relevant configuration from the given other factory.
* <p>Should include all standard configuration settings as well as
* BeanPostProcessors, Scopes, and factory-specific internal settings.
* Should not include any metadata of actual bean definitions,
* such as BeanDefinition objects and bean name aliases.
* @param otherFactory the other BeanFactory to copy from
*/
//复制其他工程的属性配置
void copyConfigurationFrom(ConfigurableBeanFactory otherFactory); /**
* Given a bean name, create an alias. We typically use this method to
* support names that are illegal within XML ids (used for bean names).
* <p>Typically invoked during factory configuration, but can also be
* used for runtime registration of aliases. Therefore, a factory
* implementation should synchronize alias access.
* @param beanName the canonical name of the target bean
* @param alias the alias to be registered for the bean
* @throws BeanDefinitionStoreException if the alias is already in use
*/
//注册bean起一个别名
void registerAlias(String beanName, String alias) throws BeanDefinitionStoreException; /**
* Resolve all alias target names and aliases registered in this
* factory, applying the given StringValueResolver to them.
* <p>The value resolver may for example resolve placeholders
* in target bean names and even in alias names.
* @param valueResolver the StringValueResolver to apply
* @since 2.5
*/
//根据StringValueResolver来移除bean
void resolveAliases(StringValueResolver valueResolver); /**
* Return a merged BeanDefinition for the given bean name,
* merging a child bean definition with its parent if necessary.
* Considers bean definitions in ancestor factories as well.
* @param beanName the name of the bean to retrieve the merged definition for
* @return a (potentially merged) BeanDefinition for the given bean
* @throws NoSuchBeanDefinitionException if there is no bean definition with the given name
* @since 2.5
*/
//返回合并后的Beandefinition
BeanDefinition getMergedBeanDefinition(String beanName) throws NoSuchBeanDefinitionException; /**
* Determine whether the bean with the given name is a FactoryBean.
* @param name the name of the bean to check
* @return whether the bean is a FactoryBean
* ({@code false} means the bean exists but is not a FactoryBean)
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
* @since 2.5
*/
//判断一个bean是否是工厂bean
boolean isFactoryBean(String name) throws NoSuchBeanDefinitionException; /**
* Explicitly control the current in-creation status of the specified bean.
* For container-internal use only.
* @param beanName the name of the bean
* @param inCreation whether the bean is currently in creation
* @since 3.1
*/
//设置一个是否真在创建的bean
void setCurrentlyInCreation(String beanName, boolean inCreation); /**
* Determine whether the specified bean is currently in creation.
* @param beanName the name of the bean
* @return whether the bean is currently in creation
* @since 2.5
*/
//指定的bean是否创建成功
boolean isCurrentlyInCreation(String beanName); /**
* Register a dependent bean for the given bean,
* to be destroyed before the given bean is destroyed.
* @param beanName the name of the bean
* @param dependentBeanName the name of the dependent bean
* @since 2.5
*/
//注册这个bean的依赖
void registerDependentBean(String beanName, String dependentBeanName); /**
* Return the names of all beans which depend on the specified bean, if any.
* @param beanName the name of the bean
* @return the array of dependent bean names, or an empty array if none
* @since 2.5
*/
//获取指定bean依赖的bean
String[] getDependentBeans(String beanName); /**
* Return the names of all beans that the specified bean depends on, if any.
* @param beanName the name of the bean
* @return the array of names of beans which the bean depends on,
* or an empty array if none
* @since 2.5
*/
String[] getDependenciesForBean(String beanName); /**
* Destroy the given bean instance (usually a prototype instance
* obtained from this factory) according to its bean definition.
* <p>Any exception that arises during destruction should be caught
* and logged instead of propagated to the caller of this method.
* @param beanName the name of the bean definition
* @param beanInstance the bean instance to destroy
*/
//销毁指定的bean
void destroyBean(String beanName, Object beanInstance); /**
* Destroy the specified scoped bean in the current target scope, if any.
* <p>Any exception that arises during destruction should be caught
* and logged instead of propagated to the caller of this method.
* @param beanName the name of the scoped bean
*/
//销毁指定返回的bean
void destroyScopedBean(String beanName); /**
* Destroy all singleton beans in this factory, including inner beans that have
* been registered as disposable. To be called on shutdown of a factory.
* <p>Any exception that arises during destruction should be caught
* and logged instead of propagated to the caller of this method.
*/
//销毁单利的bean
void destroySingletons(); }
1.对父接口中HierarchicalBeanFactory得获取父beanfactory的方法进行补全,set,get方法
2.对类的加载器进行set和get
3.属性的编辑器,类的转换器进行注册
4.2个后处理bean的后处理器的方法
5.2个跟Bean别名相关的方法、1个返回合并后的Bean定义的方法。
6.对指定的Bean 依赖情况进行返回
7.3个销毁bean的方法
8.1个安全访问上下文的方法
ConfigurableBeanFactory的更多相关文章
- java.lang.NoSuchMethodError: org.springframework.beans.factory.config.ConfigurableBeanFactory.getSingletonMutex()Ljava/lang/Object
© 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述 搭建SSH框架,没有添加事务时一切正常,最后添加完事务后报错,并且怎么弄都是一样.报错信息如下: 警告: Exception encou ...
- springIOC源码接口分析(二):ConfigurableBeanFactory
一 继承功能 1 SingletonBeanRegistry接口 此接口是针对Spring中的单例Bean设计的.提供了统一访问单例Bean的功能,类中定义了以下方法: 2 HierarchicalB ...
- spring源码:Aware接口(li)
一.spring容器中的aware接口介绍 Spring中提供了各种Aware接口,比较常见的如BeanFactoryAware,BeanNameAware,ApplicationContextAwa ...
- spring源码:核心组件(li)
一.AOP实现 Spring代理对象的产生:代理的目的是调用目标方法时我们可以转而执行InvocationHandler类的invoke方法,所以如何在InvocationHandler上做文章就是S ...
- [spring源码学习]四、IOC源码——普通bean初始化
一.代码例子 此节开始涉及到一个bean具体生成和保存的过程,仅仅涉及到最简单的bean,代码依旧是最简单的 public static void main(String[] args) { Defa ...
- Spring源码分析——BeanFactory体系之抽象类、类分析(二)
上一篇分析了BeanFactory体系的2个类,SimpleAliasRegistry和DefaultSingletonBeanRegistry——Spring源码分析——BeanFactory体系之 ...
- Spring源码分析——BeanFactory体系之抽象类、类分析(一)
上一篇介绍了BeanFactory体系的所有接口——Spring源码分析——BeanFactory体系之接口详细分析,本篇就接着介绍BeanFactory体系的抽象类和接口. 一.BeanFactor ...
- Spring源码分析——BeanFactory体系之接口详细分析
Spring的BeanFactory的继承体系堪称经典.这是众所周知的!作为Java程序员,不能错过! 前面的博文分析了Spring的Resource资源类Resouce.今天开始分析Spring的I ...
- Spring IoC容器总结(未完)
在面向对象系统中,对象封装了数据和对数据的处理,对象的依赖关系常常体现在对数据和方法的依赖上.这些依赖关系可以通过把对象的依赖注入交给框架或IOC容器来完成,这种从具体对象手中交出控制的做法是非常有价 ...
随机推荐
- log4j教程 10、PatternLayout
如果想生成基于模式的特定格式的日志信息,那么可以使用 org.apache.log4j.PatternLayout 格式化日志信息. PatternLayout类扩展抽象 org.apache.log ...
- Python-使用Magellan进行数据匹配总结
参考:http://www.biggorilla.org/zh-hans/walkt/ 使用Magellan进行数据匹配过程如下: 假设有两个数据源为A和B, A共有四列数据:(A_Column1,A ...
- JStorm文档
Jstorm的性能测试 JStorm 大概是Apache Storm 4倍, Apache Flink 1.5 倍, Twitter Heron 2 ~ 10 倍 Jstorm是一个分布式实时计算引擎 ...
- ASP.NET MVC学习---(六)CRUD例子补充
在之前,我们使用mvc做了一个crud的小例子 整个项目过程应该是能够很容易理解的 通过这个例子我们可以大概的了解mvc的基本使用方法 但是由于篇幅限制(还不如说自己懒不想写那么长...) 没有能够在 ...
- 2017.9.15 postgres使用postgres_fdw实现跨库查询
postgres_fdw的使用参考来自:https://my.oschina.net/Kenyon/blog/214953 postgres跨库查询可以通过dblink或者postgres_fdw来完 ...
- iOS小技巧 - 如何使UIView可以绑定点击事件
让我们这次直接进入正题,有时候我们想做以下这种界面: 目前我就想到三种方案: 做一个tableview,然后组织cell的界面如上图所示 做一个button子类,使得button的界面能如上图所示 做 ...
- 倍福TwinCAT(贝福Beckhoff)基础教程2.2 TwinCAT常见类型使用和转换_数组
声明和实例化数组的方法如下,你可以声明各种基本类型的数组 i: INT; array1: ARRAY [0..500] OF INT; FOR i := 0 TO 5000 DO arra ...
- SQL 关键字 'USER' 附近有语法错误怎么办
如下图所示,我想要访问我的Database1.mdf的user这张表,提示如下错误 user在SQL Server中是系统保留字,将user修改为[user]就可以了.但是直接在VS中是无法修改的 ...
- Swif语法基础 要点归纳(一)
常量和变量 用let声明常量 let m = 20 用var声明变量 var n = 0 类型推导机制 声明常量或变量时.能够不指定常量/变量类型,编译器会依据 ...
- OpenStack二三事(1)
更新系列不是教材,不说教,不讲道理,仅仅记录. OpenStack在云计算领域大热,没有理由不去了解它. 先说说我对OpenStack的感觉,开源.廉价.麻烦.大家都在用,在了解开发流程后.OpenS ...