<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:mvc="http://www.springframework.org/schema/mvc"
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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
</beans>
1.beans —— xml文件的根节点
2.xmlns ——是XML NameSpace的缩写,因为XML文件的标签名称都是自定义的,自己写的和其他人定义的标签很有可能会重复命名,而功能却不一样,所以需要加上一个namespace来区分这个xml文件和其他的xml文件,类似于java中的package。使用的语法是:
xmlns:namespace-prefix="namespaceURI"
其中namespace-prefix为自定义前缀,只要在这个XML文档中保证前缀不重复即可;namespaceURI是这个前缀对应的XML Namespace的定义。
<!--如果不写namespace-prefix,则表示默认的命名空间-->
<!--http://www.springframework.org/schema/beans中的元素可以不写前缀-->
<beans xmlns="http://www.springframework.org/schema/beans">
<!--其元素bean就是默认命名空间-->
<bean></bean>
<!--其元素import就是默认命名空间-->
<import resource="classpath:spring-mybatis.xml"/>
</beans>
<!--如果namespace-prefix=context,则表示可以使用<context:xxx>该命名空间下的元素,不是默认的命名空间需要写前缀-->
<beans xmlns:context="http://www.springframework.org/schema/context">
<context:component-scan base-package="com.sg.controller"/>
</beans>
3.xmlns:xsi ——是指xml文件遵守xml规范,xsi全名:xml schema instance,是指具体用到的schema资源文件里定义的元素所准守的规范。即http://www.w3.org/2001/XMLSchema-instance这个文件里定义的元素遵守什么标准。
4.xsi:schemaLocation——其实是Namespace为http://www.w3.org/2001/XMLSchema-instance(xsi)里的schemaLocation属性。
语法是:
xsi:schemaLocation = "键" "值"
第一个URI是定义的 XML Namespace的值,第二个URI给出Schema文档的位置,Schema处理器将从这个位置读取Schema文档,该文档的targetNamespace必须与第一个URI相匹配。
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
这里表示Namespace(键)为http://www.springframework.org/schema/beans的Schema(值)的位置为http://www.springframework.org/schema/beans/spring-beans.xsd。