zoukankan      html  css  js  c++  java
  • web.xml中通过contextConfigLocation的读取spring的配置文件

    公司的考勤系统程序,有5个spring配置文件:bean-edu.xml,bean-pub.xml,db-edu.xml,db-pub.xml,timer-system.xml,均放置于src目录下,在web.xml中配置这些文件的代码如下: 
    Java代码  收藏代码
    1. <context-param>  
    2.         <param-name>contextConfigLocation</param-name>  
    3.         <param-value>classpath:/db-pub.xml,  
    4.                      classpath:db-edu.xml,  
    5.                      classpath:bean*.xml,  
    6.                      classpath*:timer-system.xml  
    7.         </param-value>  
    8. </context-param>  
    注意:部署程序启动tomcat之后,log4j显示出  [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from class path resource [db-pub.xml]  [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from class path resource [db-edu.xml]  [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from file [E:apache-tomcat-6.0.33-windows-x86apache-tomcat-6.0.33webappsDigitalCampusWEB-INFclassesean-edu.xml]  [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from file [E:apache-tomcat-6.0.33-windows-x86apache-tomcat-6.0.33webappsDigitalCampusWEB-INFclassesean-pub.xml]  [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  -  Loading XML bean definitions from URL [file:/E:/apache-tomcat-6.0.33-windows-x86/apache-tomcat-6.0.33/webapps/DigitalCampus/WEB-INF/classes/timer-system.xml] 
    Java代码  收藏代码
    1. <context-param>  
    2.         <param-name>contextConfigLocation</param-name>  
    3.         <param-value>classpath:/db-pub.xml,  
    4.                      classpath:db-edu.xml,  
    5.                      classpath*:bean*.xml,  
    6.                      /WEB-INF/classes/timer-system.xml  
    7.                      <!--  classpath*:timer-system.xml-->  
    8.         </param-value>  
    9.     </context-param>  
    [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from class path resource [db-pub.xml]  [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from class path resource [db-edu.xml]  [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from file [E:apache-tomcat-6.0.33-windows-x86apache-tomcat-6.0.33webappsDigitalCampusWEB-INFclassesean-edu.xml]  [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from file [E:apache-tomcat-6.0.33-windows-x86apache-tomcat-6.0.33webappsDigitalCampusWEB-INFclassesean-pub.xml]  [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from ServletContext resource [/WEB-INF/classes/timer-system.xml] 
    根据以上两个例子:  1 classpath和classpath*的区别是:前者from class path resource,后者from URL。classpath:只会到你的class路径中查找找文件;  classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找.  2 带不带有/,没有区别。  3 bean*.xml查找的是以bean开头的配置文件,from file  4 classpath*:bean*.xml 为from file.  5   /WEB-INF/classes/timer-system.xml 为from ServletContext resource。 

    另外:  "**/" 表示的是任意目录;  "**/applicationContext-*.xml" 表示任意目录下的以"applicationContext-"开头的XML文件。  程序部署到tomcat后,src目录下的配置文件会和class文件一样,自动copy到应用的 WEB-INF/classes目录下 
  • 相关阅读:
    在 Windows 上测试 Redis Cluster的集群填坑笔记
    vmware安装黑苹果教程
    微信支付v3发布到iis时的证书问题
    Linux下安装SQL Server 2016(连接篇SQL Server on linux)
    Linux下安装SQL Server 2016(连接篇SQL Server on linux)
    Linux下安装SQL Server 2016(安装篇SQL Server on linux)
    Linux下安装SQL Server 2016(准备篇SQL Server on linux)
    客服端与服务端APP支付宝支付接口联调的那些坑
    ASP.NET MVC]WebAPI应用支持HTTPS的经验总结
    .net平台下C#socket通信(中)
  • 原文地址:https://www.cnblogs.com/wzhanke/p/4618935.html
Copyright © 2011-2022 走看看