SpringBoot源碼解析

看那個人好像一條狗-------------------------------------By Tony

首先來看ConfigurableApplicationContext接口

Springboot 通過在run()方法中createApplicationContext()來創(chuàng)建應用上下文触机,時序圖如下

createApplicationContext.png

下面是ConfigurableApplicationContext的繼承體系

ConfigurableApplicationContext.png

ConfigurableApplicationContext定義了一系列接口

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.
     * @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.
     * If none is supplied, default conversion rules apply.
     * @see org.springframework.core.convert.ConversionService
     * @since 3.0
     */
    String CONVERSION_SERVICE_BEAN_NAME = "conversionService";

    /**
     * Name of the LoadTimeWeaver bean in the factory. If such a bean is supplied,
     * the context will use a temporary ClassLoader for type matching, in order
     * to allow the LoadTimeWeaver to process all actual 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.
     * @since 3.1
     */
    String ENVIRONMENT_BEAN_NAME = "environment";

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

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

    /**
     * Set the unique id of this application context.
     * @since 3.0
     *  設置應用程序唯一ID
     */        
    void setId(String id);

    /**
     * Set the parent of this 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.
     * @param parent the parent context
     * @see org.springframework.web.context.ConfigurableWebApplicationContext
     *設置應用程序上下文的父上下文
     */
    void setParent(@Nullable ApplicationContext parent);

    /**
     * Set the {@code Environment} for this application context.
     * @param environment the new environment
     * @since 3.1
    *為應用上下文設置環(huán)境
     */
    void setEnvironment(ConfigurableEnvironment environment);

    /**
     * Return the {@code Environment} for this application context in configurable
     * form, allowing for further customization.
     * @since 3.1
     */
    @Override
    ConfigurableEnvironment getEnvironment();

    /**
     * Add a new BeanFactoryPostProcessor that will get applied to the internal
     * bean factory of this application context on refresh, before any of the
     * 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
     * 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
     * current event multicaster in case of a context that is already active.
     * @param listener the ApplicationListener to register
     * @see org.springframework.context.event.ContextRefreshedEvent
     * @see org.springframework.context.event.ContextClosedEvent
     *在應用上下文上面添加監(jiān)聽器
     */
    void addApplicationListener(ApplicationListener<?> listener);

    /**
     * Register the given protocol resolver with this application context,
     * allowing for additional resource protocols to be handled.
     * <p>Any such resolver will be invoked ahead of this context's standard
     * 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 an XML file, properties file, or relational database schema.
     * <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 that 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
     * on JVM shutdown unless it has already been closed at that time.
     * <p>This method can be called multiple times. Only one shutdown hook
     * (at max) will be registered for each context instance.
     * @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.
     * Can be used to access specific functionality of the underlying factory.
     * <p>Note: Do not use this to post-process the bean factory; singletons
     * will already have been instantiated before. Use a BeanFactoryPostProcessor
     * to intercept the BeanFactory setup process before beans get touched.
     * <p>Generally, this internal factory will only be accessible while the context
     * is active, that is, inbetween {@link #refresh()} and {@link #close()}.
     * The {@link #isActive()} flag can be used to check whether the 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;

}

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末秽褒,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子威兜,更是在濱河造成了極大的恐慌销斟,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,122評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件椒舵,死亡現(xiàn)場離奇詭異蚂踊,居然都是意外死亡,警方通過查閱死者的電腦和手機笔宿,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,070評論 3 395
  • 文/潘曉璐 我一進店門犁钟,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人泼橘,你說我怎么就攤上這事涝动。” “怎么了炬灭?”我有些...
    開封第一講書人閱讀 164,491評論 0 354
  • 文/不壞的土叔 我叫張陵醋粟,是天一觀的道長。 經(jīng)常有香客問我重归,道長米愿,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,636評論 1 293
  • 正文 為了忘掉前任鼻吮,我火速辦了婚禮育苟,結果婚禮上,老公的妹妹穿的比我還像新娘椎木。我一直安慰自己违柏,他們只是感情好,可當我...
    茶點故事閱讀 67,676評論 6 392
  • 文/花漫 我一把揭開白布香椎。 她就那樣靜靜地躺著漱竖,像睡著了一般。 火紅的嫁衣襯著肌膚如雪士鸥。 梳的紋絲不亂的頭發(fā)上闲孤,一...
    開封第一講書人閱讀 51,541評論 1 305
  • 那天,我揣著相機與錄音,去河邊找鬼讼积。 笑死肥照,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的勤众。 我是一名探鬼主播舆绎,決...
    沈念sama閱讀 40,292評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼们颜!你這毒婦竟也來了吕朵?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,211評論 0 276
  • 序言:老撾萬榮一對情侶失蹤窥突,失蹤者是張志新(化名)和其女友劉穎努溃,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體阻问,經(jīng)...
    沈念sama閱讀 45,655評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡梧税,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,846評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了称近。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片第队。...
    茶點故事閱讀 39,965評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖刨秆,靈堂內(nèi)的尸體忽然破棺而出凳谦,到底是詐尸還是另有隱情,我是刑警寧澤衡未,帶...
    沈念sama閱讀 35,684評論 5 347
  • 正文 年R本政府宣布尸执,位于F島的核電站,受9級特大地震影響眠屎,放射性物質(zhì)發(fā)生泄漏剔交。R本人自食惡果不足惜肆饶,卻給世界環(huán)境...
    茶點故事閱讀 41,295評論 3 329
  • 文/蒙蒙 一改衩、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧驯镊,春花似錦葫督、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,894評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至冯乘,卻和暖如春洽胶,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背裆馒。 一陣腳步聲響...
    開封第一講書人閱讀 33,012評論 1 269
  • 我被黑心中介騙來泰國打工姊氓, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留丐怯,地道東北人。 一個月前我還...
    沈念sama閱讀 48,126評論 3 370
  • 正文 我出身青樓翔横,卻偏偏與公主長得像读跷,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子禾唁,可洞房花燭夜當晚...
    茶點故事閱讀 44,914評論 2 355

推薦閱讀更多精彩內(nèi)容