本篇文章主要簡要分析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資源定位