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. WebStrom配置

    1.下载安装Node.jshttps://nodejs.org/en/download/2.配置node路径3.修改文件默认字符集

  2. canvas学习之树叶动画

    项目地址:http://pan.baidu.com/s/1geJgqen 今天用canvas做了一个树叶发芽到凋落的动画,当然还有很多不完善的地方,不过也让我体会到了,做动画技术占2分,算法占8分.这 ...

  3. stark 组件 url 二级分发的实现

    模拟 admin 组件url设计思路 项目urls 文件中: from django.contrib import admin from django.urls import path from st ...

  4. 如何设置Git SSH密钥

    1. SSH 存储在user/用户名/.ssh文件夹下 生成SSH密钥 $ ssh-keygen -t rsa -C "your_email" 2. 查看生成的公钥 $ cat ~ ...

  5. String类——StringBuilder类的源码及内存分析(java)

    相同:底层均采用字符数组value来保存字符串 区别:String类的value数组有final 修饰,指向不可改,同时private 未提供修改value数组的方法.StringBuilder类的v ...

  6. Thymeleaf使用bootstrap及其bootstrap相关插件(二)

    接上文http://www.cnblogs.com/conswin/p/7929772.html 接下来bootstrap-datepicker的简单使用. 1.引入添加js 和 css 2.然后是h ...

  7. 非常不错的地区三级联动,js简单易懂。封装起来了

    首先需要引入area.js,然后配置并初始化插件: 例: <!-- 绑定银行卡开始 --> <script src="js/area.js"></sc ...

  8. 784. Letter Case Permutation C++字母大小写全排列

    网址:https://leetcode.com/problems/letter-case-permutation/ basic backtracking class Solution { public ...

  9. flask-后台布局页面搭建4

    1.  搭建后台页面 5.1管理员登录 步骤:1.在admin视图中导入from flask import render_template,redirect,url_for.并写入一下代码. #登录 ...

  10. [hdu 6191] Query on A Tree

    Query on A Tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Othe ...