1. 程式人生 > 程式設計 >spring web.xml指定配置檔案過程解析

spring web.xml指定配置檔案過程解析

這篇文章主要介紹了spring web.xml指定配置檔案過程解析,文中通過示例程式碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-beans.xml</param-value>
</context-param>

指定多個配置檔案用,隔開。

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

在web應用啟動的,ContextLoaderListener讀取contextConfigLocation中定義的xml檔案,自動裝配ApplicationContext的配置資訊,

併產生WebApplicationContext物件,然後將這個物件放置在ServletContext的屬性裡,

這樣我們就可以在servlet裡得到WebApplicationContext(spring容器上下文)物件。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。