spinrg web 理解兩個context

來源:互聯網
上載者:User

標籤:style   listen   ext   ati   otc   應用   標籤   hand   維護   

我們知道,Spring有一個核心容器也就是ApplicationContext,所有的Spring組件都由這個ApplicationContext進行管理。但是在Web項目中,Spring會維護兩個context:

1. WebContext

第一個Context就是由DispatchServlet建立的WebContext,負責裝載web組件相關的bean,比如controllers、view resolvers、handler mapping等,對應的設定檔是{servlet-name}-servlet.xml,在上面例子中我們配置的Servlet的名字是spring,所以它預設載入spring-servlet.xml設定檔作為上下文。

但是我們也可以自己指定一個WebContext設定檔位置。

2. RootContext

RootContext是由ContextListener載入的,它主要裝載除web組件之外的應用程式組件,比如jdbc、mybatis等組件。標籤指定了RootContext設定檔的位置,並由標籤指定的Listener類進行裝載。

spinrg web 理解兩個context

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.