小知识-Spring如何获得schema文件

Spring framework 从2.0版本开始引入了xml schema,我们可以使用spring实现的各种schema来定义和扩展bean。

如以下例子:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    <!-- bean declarations here -->
</beans>

这个xml引入了http://www.springframework.org/schema/beans为缺省的namespace,的确我们经常用的就是定义bean,xml又定义了这个namespace的schema的location,这是一个url(http://www.springframework.org/schema/beans/spring-beans-2.5.xsd),如果用浏览器访问这个URL,的确可以得到这个schema。

但是,spring容器在启动时是从这个URL得到schema来验证这个xml文件的吗?
不是,你把网络断掉,spring一样运行的很好。

原来,在spring.jar中有个目录为META-INF,下面有个文件为spring.schemas,打开这个文件一看内容就知道,它把URL映射到了classpath。
例如第一行:
http/://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd
这个文件告诉spring容器到某个classpath下去寻找schema文件,而这些文件的确就在spring.jar的相应目录下。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值