spring配置文件頭文件的說明


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

</beans>

 

這個一直沒有弄明白,今天搜了下,找到一種解釋,也不是很好的解釋了我的疑問。待補充!

 

XML Schema命名空間作用:
1、避免命名沖突,像Java中的package一樣

2、將不同作用的標簽分門別類(像Spring中的tx命名空間針對事務類的標簽,context命名空間針對組件的標簽)

代碼解釋:
1、xmlns="http://www.springframework.org/schema/beans"
聲明xml文件默認的命名空間,表示未使用其他命名空間的所有標簽的默認命名空間。

2、xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
聲明XML Schema 實例,聲明后就可以使用 schemaLocation 屬性了

3、xmlns:aop="http://www.springframework.org/schema/aop"
聲明前綴為aop的命名空間,后面的URL用於標示命名空間的地址不會被解析器用於查找信息。其惟一的作用是賦予命名空間一個惟一的名稱。當命名空間被定義在元素的開始標簽中時,所有帶有相同前綴的子元素都會與同一個命名空間相關聯。

4、xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
這個從命名可以看出個大概,指定Schema的位置這個屬性必須結合命名空間使用。這個屬性有兩個值,第一個值表示需要使用的命名空間。第二個值表示供命名空間使用的 XML schema 的位置

所以我們需要什么樣的標簽的時候,就引入什么樣的命名空間和Schema 定義就可以了。

 

 http://iswift.iteye.com/blog/1657537


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM