spring ,mybatis 中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 https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <context:component-scan base-package="cn.edu.jxnu.sse"/>
    <mvc:annotation-driven/>
    <bean class="cn.edu.jxnu.sse.dao.impl.UserDaoMybatisImpl" id="userDao"/>
    <bean class="cn.edu.jxnu.sse.service.UserService">
        <property name="userDao" ref="userDao"/>
    </bean>
</beans>

这是spring的配置文件中的一段。xml文件中的每个标签(元素)表述的含义通过dtd或xsd文件来描述。如<bean 标签有哪些子元素,元素有哪些属性定义及数据类型等等,这些都可以通过dtd或xsd文件定义的规则决定。(dtd逐渐被xsd替代)

如果同一个标签在不同的xsd文件中都有定义,那么在文件中该采用那个xsd文件中定义的规则呢?为了区分来自不同的xsd标签 ,这时就需要为标签加上前缀。也就是<mvc:annotation-driven/>标签加了前缀mvc,表示元素规则来自某个特定的dtd文件,<context:component-scan base-package="cn.edu.jxnu.sse"/>加了前缀context,表示来自另一个特定的dtd文件。那么这些dtd文件在哪呢?可以在头部属性中找到。

根据前缀context找到对应的命名空间xmlns:context="http://www.springframework.org/schema/context",再从xsi:schemaLocation的属性中可以找到对应的xsd文件,https://www.springframework.org/schema/context/spring-context.xsd

对于没有前缀的标签,其命名空间 xmlns="http://www.springframework.org/schema/beans"属性值来制定,其对应的xsd文件也可以在xsi:schemaLocation属性值中找到.

xsi的命名空间是xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance",不需要提供xsd文件.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值