zoukankan      html  css  js  c++  java
  • spring xml头文件xmlns和xsi的意思

    在spring的配置中,总能看见如下的代码:

    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           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/context
                http://www.springframework.org/schema/context/spring-context-3.0.xsd
                http://www.springframework.org/schema/mvc
                http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
                default-autowire="byName">


    刚开始的时候也只是似懂非懂的照搬照用,后面同学问了我,然后去研究了一下
    首先:
    1.beans —— xml文件的根节点
    2.xmlns ——是XML NameSpace的缩写,因为XML文件的标签名称都是自定义的,自己写的和其他人定义的标签很有可能会重复命名,而功能却不一样,所以需要加上一个namespace来区分这个xml文件和其他的xml文件,类似于java中的package。
    3.xmlns:xsi ——是指xml文件遵守xml规范,xsi全名:xml schema instance,是指具体用到的schema资源文件里定义的元素所准守的规范。即http://www.w3.org/2001/XMLSchema-instance这个文件里定义的元素遵守什么标准
    4.xsi:schemaLocation——是指本文档里的xml元素所遵守的规范,这些规范都是由官方制定的,可以进你写的网址里面看版本的变动。xsd的网址还可以帮助你判断使用的代码是否合法。
    所以如下代码:
    <!-- 启用spring mvc 注解 -->
        <context:annotation-config/>
    
        <!--自动扫描-->
        <context:component-scan base-package="com.icekredit.credit.controller"/>
        <context:component-scan base-package="com.icekredit.credit.service.impl"/>
    
        <!--自动配置注解映射器和适配器-->
        <mvc:annotation-driven />
        <mvc:default-servlet-handler />
        <mvc:resources location="/static/" mapping="/static/**" />


    代码里面用到了< mvc >的标签就要先引入

    xmlns:mvc="http://www.springframework.org/schema/mvc"

    然后需要遵守的代码规范有:

    http://www.springframework.org/schema/mvc
                http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd





    转自:http://blog.csdn.net/myherux/article/details/50967342
  • 相关阅读:
    英文字典。怎样设计数据结构
    最近看的几部电影电视剧
    pylucene 中文
    提高浏览体验的五十个最佳FireFox扩展插件
    结构和细节
    <传> 《程序猿装B指南》,程序员童鞋们请认真学习
    c++ builder TTreeView customSort 实现 自定义排序
    《转》c++ 字符串系列:字符编码进阶(下)
    庆祝我又读完一本书
    c++ 回调函数深究
  • 原文地址:https://www.cnblogs.com/who-care/p/8422084.html
Copyright © 2011-2022 走看看