文章主要探究了web容器中實(shí)例化spring的相關(guān)配置簡單介紹,接下來我們看看具體內(nèi)容。
web容器中實(shí)例化spring相關(guān)配置說明:
要想在web容器實(shí)例化時加載spring容器,web.xml文件中配置如下:
1
2
3
4
5
6
7
8
|
< context-param > < param-name >contextConfigLocation</ param-name > < param-value >classpath:bean.xml</ param-value > </ context-param > <!-- 對Spring容器進(jìn)行實(shí)例化的監(jiān)聽器s --> < listener > < listener-class >org.springframework.web.context.ContextLoaderListener</ listener-class > </ listener > |
說明:
默認(rèn)情況下spring實(shí)例化時加載的是/WEB-INF/下的applicationContext.xml
<param-name>contextConfigLocation</param-name>
<param-value>classpath:bean.xml</param-value>指定了spring需要加載的文件(類路徑下的bean.xml文件)
如果配置文件有多個配置如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
< context-param > < param-name >contextConfigLocation</ param-name > < param-value > classpath*:conf/spring/applicationContext_core*.xml, classpath*:conf/spring/applicationContext_dict*.xml, classpath*:conf/spring/applicationContext_hibernate.xml, classpath*:conf/spring/applicationContext_staff*.xml, classpath*:conf/spring/applicationContext_security.xml classpath*:conf/spring/applicationContext_modules*.xml classpath*:conf/spring/applicationContext_cti*.xml classpath*:conf/spring/applicationContext_apm*.xml </ param-value > </ context-param > |
或者(使用空格隔開,如下配置:)
1
2
3
4
5
6
|
< CONTEXT-PARAM > < PARAM-NAME >contextConfigLocation</ PARAM-NAME > < PARAM-VALUE > applicationContext-database.xml applicationContext.xml </ PARAM-VALUE > </ CONTEXT-PARAM > |
總結(jié)
以上就是本文關(guān)于web容器中實(shí)例化spring相關(guān)配置解析的全部內(nèi)容,希望對大家有所幫助。如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
原文鏈接:http://blog.csdn.net/yangxueyong/article/details/6579700