http://www.cnblogs.com/as-dreamer/p/6523215.html

我们在使用Spring框架的时候首先要配置其xml文件,大量的头信息到底代表了什么呢,在这里总结下自己的理解。。。

这里是创建web工程时自带的xml文件头内容:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">

这是我们配置的Spring头信息内容:

<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

对比之下可以发现存在共性的是他们都有:声明为xml文件,版本为1.0,编码为utf-8,这些大家都容易理解。

可是xmlns:xsi.......;  xmlns......; xsi:schemaLocation......;这些配置代表了什么东东呢???

经过总结网上前辈的经验,在这里说一下自己的理解:

首先xml是一种严格的标记语言(相对于html来说),例如必须有结束标签等,另外大家知道,因为其严格的特点,并且可以根据个人的需要增加新的标签内容,常被用来用作项目的配置文件使用。

那么需要成为严格的xml标签语言就需要有其规则进行约束,我们新建的标准的xml文件包含了xmlns:xsi.......;  xmlns......; xsi:schemaLocation.....这些内容如上所示,xmlns=命名空间,xsi=xml-schema-instance(xml模板实例,标准的是这样来命名的,好官方),知道这些我们就知道标准的web.xml文件内容这些是什么了.

web.xml的头信息:

1.xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance声明该文件的内容可以使用xsi的标签库,

2.xmlns="http://xmlns.jcp.org/xml/ns/javaee"声明标签的使用范围是被javaee的开发使用的

3.xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee声明可以使用的标签库和对应的具体的标签库版本地址。

那么Spring的头信息也就是:

1.xmlns=http://www.springframework.org/schema/beans表示是spring beans的xml配置文件

2.xmlns:xsi;xmlns:context;xmlns:aop;xmlns:tx;声明可以使用标准的xml标签(xsi);也可以使用context;aop;tx等声明后的标签库的标签,即声明的xmlns:后的内容可以作为标签规则出现在xml文件中,没有包含在内的使用时会报错(作为一种严格的标记语言的特性)。

3.xsi-schemaLocation这是语法规则契约(xmlns也是;而xmlns:xsi只是声明标签的规则),=等号后面的内容就是引入的具体的标签库和对应的要在文本中使用的标签库具体版本规则的地址。

4.由于在xsi-schemaLocation中定义的是标签的属性等相关信息,xmlns:p中由于p命名空间的引入是为了简化属性property的书写格式,而p的属性是可变的,所以没有在xsi-schemaLocation中定义。

注意:在xsi-schemaLocation中最后一个http:.....与双引号”之间要有一个空格,否则会找不到地址报错。

xsi全名:xml schema instance

web-app是web.xml的根节点标签名称
version是版本的意思
xmlns是web.xml文件用到的命名空间
xmlns:xsi是指web.xml遵守xml规范
xsi:schemaLocation是指具体用到的schema资源 你不要看相关中文资料,看了就不明白了,schema就是schema~你把他翻译成对文档的限制就行了。你可能会说,dtd才是,实际上xsd和dtd是一样的~~ 加入命名空间xmlns是为了避免命名冲突。beans.xml 那里没有加前缀表示该文件默认使用的是beans.xml的语法规则。其他的命名空间如context使用该内元素就得加上它的专属前缀context。


shemaLocation的位置在jar包的MATE-INF下面的.schemas文件中找到

spring的配置文件解析(转)的更多相关文章

  1. 使用JDom解析XML文档模拟Spring的配置文件解析

    在J2EE项目中可能会涉及到一些框架的使用,最近接触到了SSH,拿Spring来说配置文件的使用是相当重要的,Spring的配置文件是一个xml文件,Spring是如何读取到配置文件并进行依赖注入的呢 ...

  2. Spring Security 入门(1-6-1)Spring Security - 配置文件解析和访问请求处理

    1.在pom.xml中添加maven坐标 <dependency> <groupId>org.springframework.security</groupId> ...

  3. 【转】Spring Boot干货系列:(二)配置文件解析

    转自:Spring Boot干货系列:(二)配置文件解析 前言 上一篇介绍了Spring Boot的入门,知道了Spring Boot使用"习惯优于配置"(项目中存在大量的配置,此 ...

  4. Spring的配置文件ApplicationContext.xml配置头文件解析

    Spring的配置文件ApplicationContext.xml配置头文件解析 原创 2016年12月16日 14:22:43 标签: spring配置文件 5446 spring中的applica ...

  5. Spring Boot干货系列:(二)配置文件解析

    Spring Boot干货系列:(二)配置文件解析 2017-02-28 嘟嘟MD 嘟爷java超神学堂   前言 上一篇介绍了Spring Boot的入门,知道了Spring Boot使用“习惯优于 ...

  6. Spring源码解析-配置文件的加载

    spring是一个很有名的java开源框架,作为一名javaer还是有必要了解spring的设计原理和机制,beans.core.context作为spring的三个核心组件.而三个组件中最重要的就是 ...

  7. MyBatis配置文件解析

    MyBatis配置文件解析(概要) 1.configuration:根元素 1.1 properties:定义配置外在化 1.2 settings:一些全局性的配置 1.3 typeAliases:为 ...

  8. Spring源码解析之:Spring Security启动细节和工作模式--转载

    原文地址:http://blog.csdn.net/bluishglc/article/details/12709557 Spring-Security的启动加载细节   Spring-Securit ...

  9. 【Spring】BeanFactory解析bean详解

    在该文中来讲讲Spring框架中BeanFactory解析bean的过程,该文之前在小编原文中有发表过,要看原文的可以直接点击原文查看,先来看一个在Spring中一个基本的bean定义与使用. pac ...

随机推荐

  1. English trip M1 - AC3 Teacher:Corrine

    课堂上内容 16,black,games The clothes is Only $. is lucky number in China. God give us black eyes,but we ...

  2. Hibernate相关的查询 --Hibernate框架基础

    接着上一篇博文:Hibernate第一个程序(最基础的增删改查) --Hibernate本例是对Hibernate查询的扩展,使用HQL语句查询 /** * HQL添加预先需要保存的测试数据 */ @ ...

  3. Fiddler拦截http请求修改数据

    1.拦截http请求 使用Fiddler进行HTTP断点调试是fiddler一强大和实用的工具之一.通过设置断点,Fiddler可以做到: ①修改HTTP请求头信息.例如修改请求头的UA,Cookie ...

  4. Centos7 下coreseek的安装

    Coreseek介绍: Sphinx默认不支持中文索引及检索,基于Sphinx开发了Coreseek 全文检索服务器,Coreseek应该是现在用的最多的Sphinx中文全文检索,它提供了为Sphin ...

  5. Kindergarten CodeForces - 484D (贪心,好题)

    大意: 给定序列, 求划分为若干段, 使得总贡献最大, 每段的贡献为max-min 可以发现最优解一定是连续一段递增或递减, 然后dp即可. #include <iostream> #in ...

  6. 迭代FFT

    int reverse(int x, int len){ ; ; i < len; i <<= ){ t <<= ; ; } return t; } Complex A[ ...

  7. leetcode-algorithms-28 Implement strStr()

    leetcode-algorithms-28 Implement strStr() mplement strStr(). Return the index of the first occurrenc ...

  8. Django之信号和序列化

    前言 Django的信号要从一张抽象图和一个需求说起: 赛道:Django 赛车:http请求 基础设施:Django设置的信号 一.Django内置信号类型 1.既然赛道上有各种基础设置,那么Dja ...

  9. zookeeper 食谱

    以示例形式说明 zk 食谱. 假定有 4 个客户端,分别执行 create -s -e /lock/read xx 或 create -s -e /lock/write 获取锁. 一.获取读锁的情况: ...

  10. dubbo 框架和 tomcat 的比较

    接触 dubbo 有一段时间,特别想拿 dubbo 和 tomcat 比较一番. tomcat 是 web 服务器,提供 http 服务,当 tomcat 收到浏览器发送的 http 请求时,根据 u ...