文章主要探究了web容器中實例化spring的相關配置簡單介紹,接下來我們看看具體內容。
web容器中實例化spring相關配置說明:
要想在web容器實例化時加載spring容器,web.xml文件中配置如下:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:bean.xml</param-value></context-param><!-- 對Spring容器進行實例化的監聽器s --><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
說明:
默認情況下spring實例化時加載的是/WEB-INF/下的applicationContext.xml
<param-name>contextConfigLocation</param-name>
<param-value>classpath:bean.xml</param-value>指定了spring需要加載的文件(類路徑下的bean.xml文件)
如果配置文件有多個配置如下:
<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>
或者(使用空格隔開,如下配置:)
<CONTEXT-PARAM> <PARAM-NAME>contextConfigLocation</PARAM-NAME> <PARAM-VALUE> applicationContext-database.xml applicationContext.xml </PARAM-VALUE> </CONTEXT-PARAM>
總結
以上就是本文關于web容器中實例化spring相關配置解析的全部內容,希望對大家有所幫助.
新聞熱點
疑難解答
圖片精選