在web.xml中通過contextConfigLocation配置spring,contextConfigLocation 參數定義了要裝入的 Spring 配置文件。
如果想裝入多個配置文件,可以在<param-value>
標記中用逗號作分隔符。
在web.xml裏配置Listener
如果在web.xml裏給該Listener指定要加載的xml,如:
xml代碼如下:
<!-- spring config -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
則會去加載相應的xml,而不會去加載/WEB-INF/下的applicationContext.xml。
但是,如果沒有指定的話,默認會去/WEB-INF/下加載applicationContext.xml。