在web.xml中通過contextConfigLocation配置spring,contextConfigLocation參數定義了要裝入的 Spring 配置文件。
部署applicationContext.xml文件
如果不寫任何參數配置,默認的是在/WEB-INF/applicationContext.xml
如果指定了要加載的文件,則會去加載相應的xml,而不會去加載/WEB-INF/下的applicationContext.xml。如果沒有指定的話,默認會去/WEB-INF/下加載applicationContext.xml。
如果想要自定義文件名,需要在web.xml中加入contextConfigLocation這個context參數
springmvc的默認配置文件是放在WEB-INF下的,并且要命名為*-servlet.xml,*為servlet—name,即下文中的"Springmvc"。
我們可以在web.xml中配置<init-param>來自定義文件名稱和位置。如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
< servlet > < servlet-name >Springmvc</ servlet-name > < servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class > <!-- 通過初始化參數,指定xml文件的位置 --> < init-param > < param-name >contextConfigLocation</ param-name > < param-value >classpath:spring-mvc.xml</ param-value > </ init-param > </ servlet > < servlet-mapping > < servlet-name >Springmvc</ servlet-name > < url-pattern >/*.do</ url-pattern > </ servlet-mapping > |
classpath:只會到你的class路徑中查找找文件;
classpath*:不僅包含class路徑,還包括jar文件中(class路徑)進行查找.
到此這篇關于Java web.xml之contextConfigLocation作用案例詳解的文章就介紹到這了,更多相關Java web.xml之contextConfigLocation作用內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/elice_/article/details/87865610