Spring源码-BeanFactory-解读

/**
 * The root interface for accessing a Spring bean container.	用于访问 Spring bean 容器的根接口
 * This is the basic client view of a bean container;			这是一个 bean 容器的基本客户端视图
 * further interfaces such as {@link ListableBeanFactory} and	更进一步的接口例如 ListableBeanFactory 和 ConfigurableBeanFactory
 * {@link org.springframework.beans.factory.config.ConfigurableBeanFactory}
 * are available for specific purposes.							可用于指定的用途
 *
 * <p>This interface is implemented by objects that hold a number of bean definitions,	这个接口被很多 bean 定义的对象所实现,
 * each uniquely identified by a String name. Depending on the bean definition,			每一个都凭借一个字符串名字唯一的被标示。依靠这个 bean definition
 * the factory will return either an independent instance of a contained object			这个工厂将返回任意一个包含对象的独立实例
 * (the Prototype design pattern), or a single shared instance (a superior				(这个原型设计模式),或者一个可共享的实例
 * alternative to the Singleton design pattern, in which the instance is a				(一个优于的单例设计模式可替代的方案,其中的实例是在这个工厂范围内的单例 )
 * singleton in the scope of the factory). Which type of instance will be returned		将根据这个 bean factory 的配置返回哪些类型的实例:
 * depends on the bean factory configuration: the API is the same. Since Spring			api 是相同的。自从 Spring 2.0 开始
 * 2.0, further scopes are available depending on the concrete application				更远的可用作用域取决于实际的 application context
 * context (e.g. "request" and "session" scopes in a web environment).					(例如在 web 环境中的 request 和 session 的作用域)
 *
 * <p>The point of this approach is that the BeanFactory is a central registry			这个方法的重点是 BeanFactory 是 application 组件的一个注册中心
 * of application components, and centralizes configuration of application				并且集中配置 application 组件
 * components (no more do individual objects need to read properties files,				(例如,单个对象不需要去阅读属性文件)
 * for example). See chapters 4 and 11 of "Expert One-on-One J2EE Design and			查看 "Expert One-on-One J2EE Design and for example) 的第 4 和 11 章
 * Development" for a discussion of the benefits of this approach.						去探讨这个方法的好处
 *
 * <p>Note that it is generally better to rely on Dependency Injection					注意,依赖注入通常使用(push 配置)通过 set 或构造函数去配置 application 的对象更好,
 * ("push" configuration) to configure application objects through setters
 * or constructors, rather than use any form of "pull" configuration like a				而不是使用任何形式的 BeanFactory 的 "pull" 配置
 * BeanFactory lookup. Spring's Dependency Injection functionality is					Spring 的依赖注入功能是使用 BeanFactory 接口和它的 子接口实现的
 * implemented using this BeanFactory interface and its subinterfaces.
 *
 * <p>Normally a BeanFactory will load bean definitions stored in a configuration		通常一个 BeanFactory 将加载存储在一个配置源(例如 xml 文档)中的 bean definitions
 * source (such as an XML document), and use the {@code org.springframework.beans}		并且使用 org.springframework.beans 这个包去配置这些 bean,
 * package to configure the beans. However, an implementation could simply return		然而一些实现能够简单的返回一个在 Java code 中被创建的 Java 对象。
 * Java objects it creates as necessary directly in Java code. There are no				这是不约束如何存储方式:LDAP,RDBMS,XML,属性文件,
 * constraints on how the definitions could be stored: LDAP, RDBMS, XML,				etc。
 * properties file, etc. Implementations are encouraged to support references			实现能够促进在支持在 bean 之间的引用(依赖注入)
 * amongst beans (Dependency Injection).
 *
 * <p>In contrast to the methods in {@link ListableBeanFactory}, all of the				与 ListableBeanFactory 中的方法有差异,
 * operations in this interface will also check parent factories if this is a			如果它是 HierarchicalBeanFactory 这个接口的所有操作都将检查父工厂
 * {@link HierarchicalBeanFactory}. If a bean is not found in this factory instance,	如果一个 bean 没有在这个工厂中建立实例,将请求直接的父工厂
 * the immediate parent factory will be asked. Beans in this factory instance			这个工厂中的 bean 应该覆盖在所有父工厂中同名的 bean
 * are supposed to override beans of the same name in any parent factory.
 *
 * <p>Bean factory implementations should support the standard bean lifecycle interfaces	bean 工厂实现应该尽可能的支持标准的生命周期接口
 * as far as possible. The full set of initialization methods and their standard order is:	全套的初始化方法和他们的标准顺序是
 * <ol>
 * <li>BeanNameAware's {@code setBeanName}									设置 bean name
 * <li>BeanClassLoaderAware's {@code setBeanClassLoader}					设置 bean 加载器
 * <li>BeanFactoryAware's {@code setBeanFactory}							设置 bean 工厂
 * <li>EnvironmentAware's {@code setEnvironment}							设置环境
 * <li>EmbeddedValueResolverAware's {@code setEmbeddedValueResolver}		设置可嵌入的值解析器
 * <li>ResourceLoaderAware's {@code setResourceLoader}						设置资源加载器
 * (only applicable when running in an application context)					仅适用于当一个 application context 运行时
 * <li>ApplicationEventPublisherAware's {@code setApplicationEventPublisher}设置 ApplicationEvent 发布者
 * (only applicable when running in an application context)					仅适用于当一个 application context 运行时
 * <li>MessageSourceAware's {@code setMessageSource}						设置 MessageSource
 * (only applicable when running in an application context)					仅适用于当一个 application context 运行时
 * <li>ApplicationContextAware's {@code setApplicationContext}				设置 ApplicationContext
 * (only applicable when running in an application context)					仅适用于当一个 application context 运行时
 * <li>ServletContextAware's {@code setServletContext}						设置 ServletContext
 * (only applicable when running in a web application context)				仅适用于当一个 application context 运行时
 * <li>{@code postProcessBeforeInitialization} methods of BeanPostProcessors执行 BeanPostProcessors 的方法
 * <li>InitializingBean's {@code afterPropertiesSet}						初始化 bean ,
 * <li>a custom init-method definition										一个自定义初始化方法的定义
 * <li>{@code postProcessAfterInitialization} methods of BeanPostProcessors	BeanPostProcessors的方法
 * </ol>
 *
 * <p>On shutdown of a bean factory, the following lifecycle methods apply:	一个 bean factory 停止时,请求以下生命周期方法
 * <ol>
 * <li>{@code postProcessBeforeDestruction} methods of DestructionAwareBeanPostProcessors
 * <li>DisposableBean's {@code destroy}
 * <li>a custom destroy-method definition
 * </ol>
 *
 * @author Rod Johnson
 * @author Juergen Hoeller
 * @author Chris Beams
 * @since 13 April 2001
 * @see BeanNameAware#setBeanName
 * @see BeanClassLoaderAware#setBeanClassLoader
 * @see BeanFactoryAware#setBeanFactory
 * @see org.springframework.context.ResourceLoaderAware#setResourceLoader
 * @see org.springframework.context.ApplicationEventPublisherAware#setApplicationEventPublisher
 * @see org.springframework.context.MessageSourceAware#setMessageSource
 * @see org.springframework.context.ApplicationContextAware#setApplicationContext
 * @see org.springframework.web.context.ServletContextAware#setServletContext
 * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization
 * @see InitializingBean#afterPropertiesSet
 * @see org.springframework.beans.factory.support.RootBeanDefinition#getInitMethodName
 * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization
 * @see DisposableBean#destroy
 * @see org.springframework.beans.factory.support.RootBeanDefinition#getDestroyMethodName
 */
public interface BeanFactory {}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值