Spring源码-ConfigurableApplicationContext-源码解读

/**
 * SPI interface to be implemented by most if not all application contexts. spi 接口将由大多数 application contexts 所实现
 * Provides facilities to configure an application context in addition		除了 ApplicationContext 所提供的 application context 客户端方法外,
 * to the application context client methods in the							还提供了配置 application context 的工具
 * {@link org.springframework.context.ApplicationContext} interface.
 *
 * <p>Configuration and lifecycle methods are encapsulated here to avoid	这里对配置和生命周期方法做了封装,以避免对 ApplicationContext 客户端代码是显而易见的
 * making them obvious to ApplicationContext client code. The present		目前的方法仅能由启动和关闭代码所使用
 * methods should only be used by startup and shutdown code.
 *
 * @author Juergen Hoeller
 * @author Chris Beams
 * @since 03.11.2003
 */
public interface ConfigurableApplicationContext extends ApplicationContext, Lifecycle, Closeable {

	/**
	 * Any number of these characters are considered delimiters between
	 * multiple context config paths in a single String value.			在一个单独的字符串值里多个 context 配置路径之间,一些数量的字符被深思熟虑的分隔符
	 * @see org.springframework.context.support.AbstractXmlApplicationContext#setConfigLocation
	 * @see org.springframework.web.context.ContextLoader#CONFIG_LOCATION_PARAM
	 * @see org.springframework.web.servlet.FrameworkServlet#setContextConfigLocation
	 */
	String CONFIG_LOCATION_DELIMITERS = ",; \t\n";

	/**
	 * Name of the ConversionService bean in the factory.	在 factory 中 ConversionService(转换服务)的名字
	 * If none is supplied, default conversion rules apply.	如果没有提供,应用默认转换规则
	 * @since 3.0
	 * @see org.springframework.core.convert.ConversionService
	 */
	String CONVERSION_SERVICE_BEAN_NAME = "conversionService";

	/**
	 * Name of the LoadTimeWeaver bean in the factory. If such a bean is supplied,	在 factory 中的 LoadTimeWeaver bean 的名字,如果提供这个 bean
	 * the context will use a temporary ClassLoader for type matching, in order		这个 context 将使用一个暂时的 ClassLoader 去做类型匹配,
	 * to allow the LoadTimeWeaver to process all actual bean classes.				按照顺序去允许 LoadTimeWeaver 去处理实际的 bean classes。
	 * @since 2.5
	 * @see org.springframework.instrument.classloading.LoadTimeWeaver
	 */
	String LOAD_TIME_WEAVER_BEAN_NAME = "loadTimeWeaver";

	/**
	 * Name of the {@link Environment} bean in the factory.		Environment bean 的名字
	 * @since 3.1
	 */
	String ENVIRONMENT_BEAN_NAME = "environment";

	/**
	 * Name of the System properties bean in the factory.		System properties bean 的名字
	 * @see java.lang.System#getProperties()
	 */
	String SYSTEM_PROPERTIES_BEAN_NAME = "systemProperties";

	/**
	 * Name of the System environment bean in the factory.		System environment bean 的名字
	 * @see java.lang.System#getenv()
	 */
	String SYSTEM_ENVIRONMENT_BEAN_NAME = "systemEnvironment";


	/**
	 * Set the unique id of this application context.	为这个 application context 设置唯一 id
	 * @since 3.0
	 */
	void setId(String id);

	/**
	 * Set the parent of this application context.									设置这个 application context 的父亲
	 * <p>Note that the parent shouldn't be changed: It should only be set outside	注意父对象不应该被改变:
	 * a constructor if it isn't available when an object of this class is created,
	 * for example in case of WebApplicationContext setup.							只有在创建此类的对象时(例如在WebApplicationContext设置的情况下)
	 * @param parent the parent context												构造函数不可用时,才应在构造函数外部设置它
	 * @see org.springframework.web.context.ConfigurableWebApplicationContext
	 */
	void setParent(@Nullable ApplicationContext parent);

	/**
	 * Set the {@code Environment} for this application context.					为这个 application context 设置 Environment
	 * @param environment the new environment
	 * @since 3.1
	 */
	void setEnvironment(ConfigurableEnvironment environment);

	/**
	 * Return the {@code Environment} for this application context in configurable	返回 application context Environment 的可配置表单,
	 * form, allowing for further customization.									允许进一步定制
	 * @since 3.1
	 */
	@Override
	ConfigurableEnvironment getEnvironment();

	/**
	 * Add a new BeanFactoryPostProcessor that will get applied to the internal		添加一个新的 BeanFactoryPostProcessor,它将在刷新时
	 * bean factory of this application context on refresh, before any of the		应用于此 application context 的内部 bean factory,在所有 bean definitions 得到解析之前
	 * bean definitions get evaluated. To be invoked during context configuration.	在上下文配置期间被调用。
	 * @param postProcessor the factory processor to register
	 */
	void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor);

	/**
	 * Add a new ApplicationListener that will be notified on context events		添加一个新的 ApplicationListener ,它将在上下文事件例如刷新和终止时被通知
	 * such as context refresh and context shutdown.
	 * <p>Note that any ApplicationListener registered here will be applied			请注意,如果上下文尚未处于活动状态,
	 * on refresh if the context is not active yet, or on the fly with the			则在刷新时将应用在此注册的任何ApplicationListener,
	 * current event multicaster in case of a context that is already active.		如果上下文已处于活动状态,则将使用当前事件Multicast动态应用。
	 * @param listener the ApplicationListener to register
	 * @see org.springframework.context.event.ContextRefreshedEvent
	 * @see org.springframework.context.event.ContextClosedEvent
	 */
	void addApplicationListener(ApplicationListener<?> listener);

	/**
	 * Register the given protocol resolver with this application context,			注册给定的协议解析器给这个 application context,
	 * allowing for additional resource protocols to be handled.					允许处理额外的资源协议
	 * <p>Any such resolver will be invoked ahead of this context's standard		任何这样的解析器都将在 context 解析标准规则之前被调用
	 * resolution rules. It may therefore also override any default rules.			因此他还可以覆盖任何的默认规则
	 * @since 4.3
	 */
	void addProtocolResolver(ProtocolResolver resolver);

	/**
	 * Load or refresh the persistent representation of the configuration, which	加载或刷新配置的持久化模型,
	 * might be from Java-based configuration, an XML file, a properties file, a	可能是基于 Java 的配置,xml 文件,一个 properties 文件,一个 关系型数据化或其他形式
	 * relational database schema, or some other format.
	 * <p>As this is a startup method, it should destroy already created singletons	这个启动方法,如果它失败了应该杀掉已经被创建的单例
	 * if it fails, to avoid dangling resources. In other words, after invocation	以避免悬空的资源。换句话说,调用这个方法以后
	 * of this method, either all or no singletons at all should be instantiated.	要么全部或没有一个被实例化
	 * @throws BeansException if the bean factory could not be initialized
	 * @throws IllegalStateException if already initialized and multiple refresh
	 * attempts are not supported
	 */
	void refresh() throws BeansException, IllegalStateException;

	/**
	 * Register a shutdown hook with the JVM runtime, closing this context			在 jvm 运行时注册一个终止的钩子函数,
	 * on JVM shutdown unless it has already been closed at that time.				在 jvm 关闭时关闭这个 context,除非它已经被关闭
	 * <p>This method can be called multiple times. Only one shutdown hook			这个方法可以被多次调用。
	 * (at max) will be registered for each context instance.						每一个 context 实例最多只会被注册一个结束钩子
	 * @see java.lang.Runtime#addShutdownHook
	 * @see #close()
	 */
	void registerShutdownHook();

	/**
	 * Close this application context, releasing all resources and locks that the
	 * implementation might hold. This includes destroying all cached singleton beans.
	 * <p>Note: Does <i>not</i> invoke {@code close} on a parent context;
	 * parent contexts have their own, independent lifecycle.
	 * <p>This method can be called multiple times without side effects: Subsequent
	 * {@code close} calls on an already closed context will be ignored.
	 */
	@Override
	void close();

	/**
	 * Determine whether this application context is active, that is,
	 * whether it has been refreshed at least once and has not been closed yet.
	 * @return whether the context is still active
	 * @see #refresh()
	 * @see #close()
	 * @see #getBeanFactory()
	 */
	boolean isActive();

	/**
	 * Return the internal bean factory of this application context.				返回这个 application context 内置的 bean factory
	 * Can be used to access specific functionality of the underlying factory.		用来访问底层工厂的特定功能
	 * <p>Note: Do not use this to post-process the bean factory; singletons		注意:不要使用这个来对 bean factory 进行后期处理
	 * will already have been instantiated before. Use a BeanFactoryPostProcessor	单例在这之前已经被实例化了
	 * to intercept the BeanFactory setup process before beans get touched.			使用 BeanFactoryPostProcessor 去拦截 BeanFactory 建立过程,在 bean 被使用之前
	 * <p>Generally, this internal factory will only be accessible while the context通常这个内部的工厂仅当这个 context 激活时能够访问
	 * is active, that is, in-between {@link #refresh()} and {@link #close()}.		即在 refresh 和 close 之间
	 * The {@link #isActive()} flag can be used to check whether the context		isActive 的标志能够检查 context 是否处于 合适的状态
	 * is in an appropriate state.
	 * @return the underlying bean factory
	 * @throws IllegalStateException if the context does not hold an internal
	 * bean factory (usually if {@link #refresh()} hasn't been called yet or
	 * if {@link #close()} has already been called)
	 * @see #isActive()
	 * @see #refresh()
	 * @see #close()
	 * @see #addBeanFactoryPostProcessor
	 */
	ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException;

}

重要方法

方法名含义
void setParent(@Nullable ApplicationContext parent);设置父 application context
void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor);添加一个新的 BeanFactoryPostProcessor
void refresh() throws BeansException, IllegalStateException;加载或刷新配置的持久化模型,
void registerShutdownHook();在 jvm 运行时注册一个终止的钩子函数,
ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException;返回这个 application context 内置的 bean factory
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值