xml文档中的头部标签说明:
<?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: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">
<context:component-scan base-package="xxx.xxx.controller" />
<context:annotation-config/>
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>
<mvc:resources mapping="/images/**" location="/images/" />
<bean id="xxx" class="xxx.xxx.xxx.Xxx">
<property name="xxx" value="xxxx"/>
</bean>
</beans>
xmlns - XML Namespace的缩写
使用语法: xmlns:namespace-prefix="namespaceURI"。其中namespace-prefix为自定义前缀,只要在这个XML文档中保证前缀不重复即可;namespaceURI是这个前缀对应的XML Namespace的定义.
xmlns:xsi表示使用xsi作为前缀的Namespace,当然前缀xsi需要在文档中声明。
xsi:schemaLocation有何作用?
xsi:schemaLocation属性其实是Namespace为http://www.w3.org/2001/XMLSchema-instance里的schemaLocation属性,正是因为我们一开始声明了
|
1
|
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相匹配,例如:
|
1
2
|
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
本文解析了Spring框架中XML配置文件的结构与用法,详细介绍了关键标签如<beans>、<context:component-scan>、<context:annotation-config>等的作用及配置方式,并解释了如何通过xmlns和xsi:schemaLocation进行命名空间声明及Schema位置指定。
5万+

被折叠的 条评论
为什么被折叠?



