web.xml中通过contextConfigLocation的读取spring的配置文件

公司的考勤系统程序,有5个spring配置文件:bean-edu.xml,bean-pub.xml,db-edu.xml,db-pub.xml,timer-system.xml,均放置于src目录下,在web.xml中配置这些文件的代码如下:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/db-pub.xml,
classpath:db-edu.xml,
classpath:bean*.xml,
classpath*:timer-system.xml
</param-value>
</context-param>

[color=red]注意:[/color]部署程序启动tomcat之后,log4j显示出
[main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions [color=red]from class path resource[/color] [db-pub.xml]
[main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions [color=red]from class path resource [/color][db-edu.xml]
[main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions [color=red]from file[/color] [E:\apache-tomcat-6.0.33-windows-x86\apache-tomcat-6.0.33\webapps\DigitalCampus\WEB-INF\classes\bean-edu.xml]
[main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions[color=red] from file[/color] [E:\apache-tomcat-6.0.33-windows-x86\apache-tomcat-6.0.33\webapps\DigitalCampus\WEB-INF\classes\bean-pub.xml]
[main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions[color=red] from URL[/color] [file:/E:/apache-tomcat-6.0.33-windows-x86/apache-tomcat-6.0.33/webapps/DigitalCampus/WEB-INF/classes/timer-system.xml]



<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/db-pub.xml,
classpath:db-edu.xml,
classpath*:bean*.xml,
/WEB-INF/classes/timer-system.xml
<!-- classpath*:timer-system.xml-->
</param-value>
</context-param>



[main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions [color=red]from class path resource[/color] [db-pub.xml]
[main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions [color=red]from class path resource[/color] [db-edu.xml]
[main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions [color=red]from file[/color] [E:\apache-tomcat-6.0.33-windows-x86\apache-tomcat-6.0.33\webapps\DigitalCampus\WEB-INF\classes\bean-edu.xml]
[main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions [color=red]from file[/color] [E:\apache-tomcat-6.0.33-windows-x86\apache-tomcat-6.0.33\webapps\DigitalCampus\WEB-INF\classes\bean-pub.xml]
[main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions [color=red]from ServletContext resource[/color] [/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目录下
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值