spring xml文件中xsd的作用

我们在打开一个spring xml配置文件的时候,经常会在前几行看到这样的一堆链接。

<beans xmlns="http://www.springframework.org/schema/beans" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:mvc="http://www.springframework.org/schema/mvc" 
  xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	   http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
	   http://www.springframework.org/schema/aop
	   http://www.springframework.org/schema/aop/spring-aop.xsd
	   http://www.springframework.org/schema/mvc
	   http://www.springframework.org/schema/mvc/spring-mvc.xsd
	   http://www.springframework.org/schema/tx
	   http://www.springframework.org/schema/tx/spring-tx.xsd
	   http://www.springframework.org/schema/task
	   http://www.springframework.org/schema/task/spring-task.xsd">
</beans>

那么这堆东西的作用是什么呢?

其实,这就是在spring加载bean配置的时候检查xml文件中各个标签以及标签之间的书写格式是否正确的一个配置单。例如标签里边可以嵌套标签,里边可以有id属性等等。开发者写完配置文件后,应用启动时spring需要检查里边的标签是否正确,这就需要“对照标准答案”了,这些链接里边其实你复制到浏览器打开就会发现,里边就是一个个的文本文件。

例如,我们打开http://www.springframework.org/schema/beans/,其内容如下,就是各个版本的beans标签的约束文件的列表。

在这里插入图片描述
也就是说红色箭头指向的便签指定的是标签配置文件的约束文件列表,绿色箭头指向的是具体使用哪个版本的约束文件(没有写版本号默认用最新的)。

在这里插入图片描述
常用的便签约束文件有aop/beans/context/tx等。另外在spring启动的时候会到链接指定的位置寻找约束文件,如果断网的话应用可能会启动不起来,所以spring会在一些jar包中放置了一些默认的xsd文件,作为本地缓存,无网的情况下加载本地缓存文件,所以大家最好不要指定xsd文件的版本号,这样会很容易找不到xsd文件,不指定版本号的话会默认寻找最新版本的xsd。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值