本篇文章主要简要分析applicationContext.xml结构。
通过如下步骤添加Spring Config 类型的文件
会默认出现如下结构的配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
下面,我们来分析该配置文件
1. 指定xml文件的版本和编码格式
<?xml version="1.0" encoding="UTF-8"?>
2.默认命名空间
xmlns="http://www.springframework.org/schema/beans"
3.xml元素应遵循的规范
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4.xml标签遵循的规范
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
5.定义xmlschema地址,由两部分组成,前面部分就是命名空间,后面部分是xsd(xmlschema)
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
6.几个缩写词
version:指版本
xmlns:xml namespace的缩写,命名空间的意思
xsi:XMLSchema-instance缩写
xmlns:xsi :两部分构成,前部分是命名空间,后部分是前缀,整体表示xml元素应遵循的规范
xsi:schemaLocation 指具体用到的schema资源定位