web.xml中contextConfigLocation的作用(轉)


原文地址:http://blog.csdn.net/zhangliao613/article/details/6289114

原文格式較亂,此處略作整理。內容未變。

在web.xml中使用contextConfigLocation參數定義要裝入的Spring配置文件。

 

1. 在web.xml里配置需要加載的spring配置文件。
  如果要裝入多個配置文件,在<param-value>標記中用逗號作分隔符即可。

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-base.xml,classpath:spring-another.xml</param-value>
    </context-param>

 

2. 在web.xml里配置Listener,本Listener會去加載第一步中指定的配置文件。

   <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
   </listener>

 

3. 如果指定了要加載的文件,則會去加載相應的xml,而不會去加載/WEB-INF/下的applicationContext.xml。(指定加載即是第1步的配置)
  如果沒有指定的話,默認會去/WEB-INF/下加載applicationContext.xml。

 

4. 多個配置文件里的交叉引用可以用ref的external或bean解決

    <bean id="userService" class="domain.user.service.impl.UserServiceImpl">
        <property name="dbbean">
             <ref bean="dbBean"/>
        </property>
    </bean>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM