两种格式的配置文件:

DTD和Schema区别:

Schema是对XML文档结构的定义和描述,其主要的作用是用来约束XML文件,并验证XML文件有效性。DTD的作用是定义XML的合法构建模块,它使用一系列的合法元素来定义文档结构。它们之间的区别有下面几点:

1、Schema本身也是XML文档,DTD定义跟XML没有什么关系,Schema在理解和实际应用有很多的好处。

2、DTD文档的结构是“平铺型”的,如果定义复杂的XML文档,很难把握各元素之间的嵌套关系;Schema文档结构性强,各元素之间的嵌套关系非常直观。

3、DTD只能指定元素含有文本,不能定义元素文本的具体类型,如字符型、整型、日期型、自定义类型等。Schema在这方面比DTD强大。

4、Schema支持元素节点顺序的描述,DTD没有提供无序情况的描述,要定义无序必需穷举排列的所有情况。Schema可以利用xs:all来表示无序的情况。

5、对命名空间的支持。DTD无法利用XML的命名空间,Schema很好满足命名空间。并且,Schema还提供了include和import两种引用命名空间的方法。

这里主要讲解spring的配置文件的命名空间

1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"  <!--默认命名空间:表示未使用其他命名空间的所有标签的默认命名空间-->
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   <!--xsi标准命名空间,用于指定义自定义命名空间的schema文件,声明后就可以使用 schemaLocation 属性了-->
4 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">  <!--此处可以不配置,可以用来引用schema在本地的副本-->
5   
6
7
8 </beans>

为每个命名空间指定了对应的Schema文档的时候,定义的语法为:

  “全称命名空间1  空格  全称命名空间1对应的Schema文件空格”

其他命名空间与

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

同一级别下配置即可

  • util

util标签用来配置集合、常量等的

xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation中需要定义
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd

  使用:分别使用<util:list>、<util:map>、<util:set>、<util:properties>等标签,用来 

     取代ListFactoryBean、MapFactoryBean、SetFactoryBean、PropertiesFactoryBean。
  用途一:直接使用<util:properties id="appProps" location="classpath:META-INF/app.properties" />指定了配置文件
    以前需要使用
      <!-- creates a java.util.Properties instance with values loaded from the supplied location -->
        <bean id="jdbcConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
          <property name="location" value="classpath:com/foo/jdbc-production.properties"/>
        </bean>
    spring中id就是这个类的一个别名
    现在只需使用
      <!-- creates a java.util.Properties instance with values loaded from the supplied location -->
        <util:properties id="jdbcConfiguration" location="classpath:com/foo/jdbc-production.properties"/>

    

  • jee

jee标签用来处理javaee标准相关的问题,例如查询一个jndi对象以及定义一个ejb的引用等

xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation中需要定义
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
  • lang

lang用来将那些已经被定义在一些动态语言(例如Jruby和Groovy)中的对象作为beans中的对象存放到spring容器中

xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation中需要定义
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
  • jms

xmlns:jms="http://www.springframework.org/schema/jms"
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
  • tx (transaction)

使用时建议配合aop

xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
  • aop

xmlns:aop="http://www.springframework.org/schema/aop"
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
  • context

xmlns:context="http://www.springframework.org/schema/context"
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  • jdbc

xmlns:jdbc="http://www.springframework.org/schema/jdbc"
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
  • cache

xmlns:jdbc="http://www.springframework.org/schema/cache"
http://www.springframework.org/schema/cache http://www.springframework.org/schema/jdbc/spring-cache.xsd
  • 完整的一个配置文件头如下

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.1.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-4.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd"> </beans>

reference:

[1] http://iswift.iteye.com/blog/1657537

[2] http://www.cnblogs.com/brolanda/p/4167553.html

SPRING---------配置文件的命名空间的更多相关文章

  1. Spring配置文件的命名空间URI

    Spring配置文件介绍 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=" ...

  2. XML配置文件的命名空间与Spring配置文件中的头

    一直以来,写Spring配置文件,都是把其他配置文件的头拷贝过来,最多改改版本号,也不清楚哪些是需要的,到底是干嘛的.今天整理一下,拒绝再无脑copy. 一.Spring配置文件常见的配置头 < ...

  3. Spring配置文件中未引入dubbo命名空间头部配置而引起的错误案例

    问题描述: Spring配置文件中未引入dubbo命名空间的头部配置而引起项目启动时报出如下错误信息: org.springframework.beans.factory.xml.XmlBeanDef ...

  4. 你不知道的Spring配置文件

    Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".Java EE程序员必须学会并灵活应用这份"图纸&quo ...

  5. spring配置文件头部xmlns配置精髓

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...

  6. Spring配置文件的xsd知识点

    今天在Spring配置文件中配置如下事务属性时,提示<tx is not bound(不受约束的),估计是配置文件的xsd没配置好. <!-- 2.配置事务属性 --> <tx ...

  7. Spring学习笔记--Spring配置文件和依赖注入

    Spring配置文件 1.alias:设置别名,为bean设置别名,并且可以设置多个别名; <!-- 设置别名 --> <alias name="user" al ...

  8. spring 配置文件的头部 xmls

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...

  9. spring配置文件引入properties文件:<context:property-placeholder>标签使用总结

    一.问题描述: 1.有些参数在某些阶段中是常量,比如: (1)在开发阶段我们连接数据库时的连接url.username.password.driverClass等 (2)分布式应用中client端访问 ...

  10. Spring配置文件<context:property-placeholder>标签使用漫谈

    <context:property-placeholder>标签提供了一种优雅的外在化参数配置的方式,不过该标签在Spring配置文件中只能存在一份!!! 众所周知,Spring容器是采用 ...

随机推荐

  1. C++操作符的优先级 及其记忆方法

    优先级 操作符 描述 例子 结合性 1 ()[]->.::++-- 调节优先级的括号操作符数组下标访问操作符通过指向对象的指针访问成员的操作符通过对象本身访问成员的操作符作用域操作符后置自增操作 ...

  2. 【ARM】串行通信

    异步通信 所谓异步通信,是指数据传送以字符为单位,字符与字符间的传送是完全异步的,位与位之间的传送基本是同步的.   异步串行通信的特点可以概括如下 1)以字符为单位传送信息 2)相邻两字符间的间隔是 ...

  3. sql语句插入百万测试数据

    开发的过程中,很多时候我们需要插入百万数据来测试功能和性能,今天我来教大家最简单的插入方法 -----------------1.新建表--------------------- CREATE TAB ...

  4. 使用typed.js实现页面上的写字功能

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. python2 和 python3 区别

    python2 python 2 必须加object加入后是新式类 python 2 不加object是经典类 class HTTP(object): # 经典类和新式类 @staticmethod ...

  6. 3. 哈工大LTP解析

    1. 通俗易懂解释知识图谱(Knowledge Graph) 2. 知识图谱-命名实体识别(NER)详解 3. 哈工大LTP解析 1. 前言 哈工大语言技术平台Language Technology ...

  7. Spark Shuffle 中 JVM 内存使用及配置内幕详情

      本课主题 JVM 內存使用架构剖析 Spark 1.6.x 和 Spark 2.x 的 JVM 剖析 Spark 1.6.x 以前 on Yarn 计算内存使用案例 Spark Unified M ...

  8. 【MySql 】is not allowed to connect to this MySql server 无法访问远程MySQL数据库

    问题:访问远程MySQL数据库时报错[is not allowed to connect to this MySql server ]不允许访问,因为MySQL默认只有本机localhost能够访问M ...

  9. Spark 介绍(基于内存计算的大数据并行计算框架)

    Spark 介绍(基于内存计算的大数据并行计算框架)  Hadoop与Spark 行业广泛使用Hadoop来分析他们的数据集.原因是Hadoop框架基于一个简单的编程模型(MapReduce),它支持 ...

  10. Could not read symbols解决方法

    Could not read symbols 陈运文 Could not read symbols:Linux/UNIX系统下编译时,常见的一类报错信息. 通常情况下,该编译报错信息之前会给出出现错误 ...