spring 整合了各种工具,并且spring提供了对各种工具的xml scheme 的配置方式,简化了开发。
但是对于各种工具的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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
</beans>
 
首先xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
是必须存在的,可以从spring的文档和例子中查找到,
xsi:schemaLocation 指定了用于解析和校验xml的定义文件(xsd)的位置。
我们以添加aop命名空间为例:
在spring.jar文件中的META—INF目录中提供了spring.schemas 文件,这个文件指定了提供支持的功能的
xml元素配置的命名空间定义文件的位置,在这个文件中我们可以找到aop的位置:
http\://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd
http\://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsd
http\://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-2.5.xsd
那么我们可以在spring.jar文件的对应目录中找到这些xsd文件,打开文件以后,
可以看到标签:<xsd:schema xmlns="http://www.springframework.org/schema/aop"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:tool="http://www.springframework.org/schema/tool"
  targetNamespace="http://www.springframework.org/schema/aop"
  elementFormDefault="qualified"
  attributeFormDefault="unqualified">
那么第一个xmlns就是要引进的命名空间,但是在引进applicationContext.xml之前需要修改为:
xmlns:aop="http://www.springframework.org/schema/aop",之后添加入applicationContext.xml文件中,且一定要放置于xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"之后,顺序不能错。
而/spring-aop-2.5.xsd就是aop的元素的定义的文件名

Spring命名空间引入方法的更多相关文章

  1. Springmvc+Spring+Hibernate搭建方法

    Springmvc+Spring+Hibernate搭建方法及example 前面两篇文章,分别介绍了Springmvc和Spring的搭建方法,本文再搭建hibernate,并建立SSH最基本的代码 ...

  2. Spring中引入其他配置文件

    一.引入其他 模块XML 在Spring的配置文件,有时候为了分模块的更加清晰的进行相关实体类的配置. 比如现在有一个job-timer.xml的配置 <?xml version="1 ...

  3. Spring基本使用方法_Bean对象

    Spring基本使用方法_Bean对象 Struts与Hibernate可以做什么事? Struts MVC中控制层解决方案.可以进行请求数据自动封装,类型转换,文件上传,效验..... Hibern ...

  4. Spring配置文件引入xml文件: <import resource=" " />标签使用总结

    引入其他模块XML 在Spring的配置文件,有时候为了分模块的更加清晰的进行相关实体类的配置. 比如现在有一个job-timer.xml的配置 <?xml version="1.0& ...

  5. Spring入门(3)-Spring命名空间与Bean作用域

    Spring入门(3)-Spring命名空间与Bean作用域 这篇文章主要介绍Spring的命名空间和Bean作用域 0. 目录 Spring命名空间 Bean作用域 1. Spring命名空间 在前 ...

  6. Ⅳspring的点点滴滴--方法和事件

    承接上文 方法和事件 .net篇(环境为vs2012+Spring.Core.dll v1.31) public abstract class MethodDemo { protected abstr ...

  7. Spring 通过工厂方法(Factory Method)来配置bean

    Spring 通过工厂方法(Factory Method)来配置bean 在Spring的世界中, 我们通常会利用bean config file 或者 annotation注解方式来配置bean. ...

  8. CSS基础-引入方法,选择器,继承

    一.CSS引入方法:行内式.嵌入式.导入式.链接式. 1.行内式. 即:在标签的style属性中设定CSS样式. 例子:<div style="行内式</div> 2.嵌入 ...

  9. Springmvc+Spring+Hibernate搭建方法及实例

    Springmvc+Spring+Hibernate搭建方法及实例  

随机推荐

  1. jquery data的用法

    jquery data和 jquery attr, js getAttribute 有着本质的区别,并且无法用$(el).data('property')的方法,去获取$(el).attr('data ...

  2. php设置错误级别

    ini_set('display_errors', 1); error_reporting(E_ALL);

  3. Eclipse Git分支实战

    切换分支 右键工程,创建新分支 命名新分支 点击finish,可以看到项目已经切换到hot_fix 修改代码: Ctrl+#提交到本地仓库,之后提交到远程仓库 Next,Finish 等待一下, 点击 ...

  4. minicom - 友好易用的串口通信程序

    总览 SYNOPSIS minicom [-somMlwz8] [-c on|off] [-S script] [-d entry] [-a on|off] [-t term] [-p pty] [- ...

  5. js的cookie写入存储与读取

    js的cookie写入存储与读取 在路径url截取需要的数据,存储到cookie里,读取成功并实现跳转. //写cookies 过期时间 2小时后 function setCookie(c_name, ...

  6. Windows 实用软件

    Useful tool Listary Ditto Winsnap Quick Look Myper Splash GifCam ScreenToGif Free Download Manage Si ...

  7. linux c++下遍历文件

    https://blog.csdn.net/u013617144/article/details/44807333

  8. GUI学习之n——自定义信号

    PyQt中是依靠信号——槽的机制来运行,可是有些时候需要我们定义一下些新的信号以满足使用要求,例如按钮是没有右击的效果,那我们怎么创建一个新的信号呢? 首先要注意,新的信号是要以类属性的形式来定义 c ...

  9. vecto容器中一些没有注意到的地方

    vector容器 vectoor是一个单口容器. vector动态增长的基本原理 当插入新元素的时候,如果空间不足,那么vector会重新申请更大的一块内存空间,将原空间数据拷贝到新空间,释放旧空间的 ...

  10. Ansible笔记(2)--配置清单

    一.Ansible Inventory配置及详解 Inventory是ansible管理主机信息的配置文件,默认存放在/etc/ansible/hosts.在使用时通过 -i 或 --inventor ...