Spring在web.xml中的配置詳細(xì)介紹
Spring在web.xml中的配置詳細(xì)介紹
前言
在實際項目中spring的配置文件applicationcontext.xml是通過spring提供的加載機制自動加載到容器中。在web項目中,配置文件加載到web容器中進行解析。目前,spring提供了兩種加載器,以供web容器的加載:一種是ContextLoaderListener,另一種是ContextLoaderServlet。這兩種在功能上完全相同,只是前一種是基于Servlet2.3版本中新引入的Listener接口實現(xiàn),而后一種是基于Servlet接口實現(xiàn),以下是這兩種加載器在web.xml中的配置應(yīng)用:
ContextLoaderListener
<listener> <listener-class>org.springframework.context.ContextLoaderListener</listener-class> </listener>
ContextLoaderServlet
<servlet> <servlet-name>context</servlet-name> <servlet-class>org.springframework.context.ContextLoaderServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
通過上面的配置,web容器會自動加載applicationcontext.xml初始化。
如果需要指定配置文件的位置,可通過context-param加以指定:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/myApplicationContext.xml</param-value> </context-param>
之后,可以通過WebApplicationContextUtils.getWebApplicationContext方法在web應(yīng)用中獲取applicationcontext的引用。
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
J2ME/J2EE實現(xiàn)用戶登錄交互 實現(xiàn)代碼
用手機客戶端進行登錄服務(wù)器,然后返回消息進行交互.2009-07-07jsp使用sessionScope獲取session案例詳解
這篇文章主要介紹了jsp使用sessionScope獲取session案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08

AJAX自學(xué)練習(xí) 無刷新從數(shù)據(jù)庫后臺取數(shù)據(jù)顯示

jsp SmartUpload 實現(xiàn)上傳功能代碼