java配置文件头

<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:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">
</beans>

xmlns:是一个保留字,用于绑定该xml文档默认的命名空间,以将此xml和其它xml文档中的元素名称区分开来。(含义为xml namespace,即xml命名空间。)命名空间就像java中的包一样,用来防止元素名称的重复带来不必要的麻烦。xmlns是spring配置文件的默认命名空间,在<beans></beans>范围中,所有没有前缀的元素,都要去该命名空间的地址(注意是去其地址下面,其地址下面才会存有名称的定义)中寻找定义,如果找不到就会报错;

前缀

前缀用于在此xml文档中,区别不同作用的相同名称。

xsi:前缀,代表XMLSchema-instance,即XML Schema 实例,声明后就可以使用 schemaLocation 属性了,前缀和命名空间绑定在一起,则在命名空间作用范围内,就可以使用前缀代替命名空间去声明元素;

aop:同样是前缀,这个代号是由开发人员自己起的(你如果高兴,也可以叫它aaoopp),但在下边声明一个元素时,要和这里保持一致;

context:同上;

xsi:schemaLocation有何作用

    xsi:schemaLocation属性其实是Namespace为http://www.w3.org/2001/XMLSchema-instance里的schemaLocation属性,正是因为我们一开始声明了

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

里才写作xsi:schemaLocation(当然一般都使用这个前缀)。它定义了XML Namespace和对应的 XSD(Xml Schema Definition)文档的位置的关系。它的值由一个或多个URI引用对组成,两个URI之间以空白符分隔(空格和换行均可)。第一个URI是定义的 XML Namespace的值,第二个URI给出Schema文档的位置,Schema处理器将从这个位置读取Schema文档,该文档的targetNamespace必须与第一个URI相匹配。例如:

xsi:schemaLocation="http://www.springframework.org/schema/context 

                    http://www.springframework.org/schema/context/spring-context.xsd"

 这里表示Namespace为http://www.springframework.org/schema/context的Schema的位置为http://www.springframework.org/schema/context/spring-context.xsd

参考文献:https://www.cnblogs.com/zhao1949/p/5652167.html

                  https://www.cnblogs.com/gonjan-blog/p/6637106.html

猜你喜欢

转载自blog.csdn.net/qq_22339269/article/details/82891785