applicationContext-XXX.xml和XXX-servlet.xml的區別

來源:互聯網
上載者:User

標籤:rda   context   cat   解釋   bottom   ack   全域   base   scan   

1.ApplicationContext.xml  是spring 全域設定檔,用來控制spring 特性的

2.dispatcher-servlet.xml 是spring mvc裡面的,控制器、攔截uri轉寄view

3.一個bean如果在兩個檔案中都被定義了(比如兩個檔案中都定義了component scan掃描相同的package), spring會在application context和 servlet context中都產生一個執行個體,他們處於不同的上下文空間中,他們的行為方式是有可能不一樣的。

4.如果在application context和 servlet context中都存在同一個 @Service 的執行個體, controller(在servlet context中) 通過 @Resource引用時, 會優先選擇servlet context中的執行個體。

5.根據官網解釋servlet context可以引用application context裡的執行個體,反之不可以。

6.多個servlet共用application context裡的執行個體

7.建議使用方法:servlet只掃描@controler;application掃描其它

servlet.xml掃描配置

<!-- 掃描包 裡的註解產生bean -->
<context:component-scan base-package="com.ssm.controller" use-default-filters="false">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>

ApplicationContext.xml 掃描配置

<context:component-scan base-package="com.ssm" use-default-filters="true">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>

applicationContext-XXX.xml和XXX-servlet.xml的區別

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.