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. Neo4j源代码分析

    1.下载neo4j源码 https://github.com/neo4j/neo4j/ 参考文章 原文地址:https://blog.csdn.net/e15273/article/details/7 ...

  2. Label显示时间

    package 第十一章; import java.awt.Button; import java.awt.Color; import java.awt.Font; import java.awt.F ...

  3. 在webpack中配置.vue组件页面的解析

    1. 运行`cnpm i vue -S`将vue安装为运行依赖: 2. 运行`cnpm i vue-loader vue-template-compiler -D`将解析转换vue的包安装为开发依赖: ...

  4. python3中编码与解码的问题

    python3中编码与解码的问题 ASCII .Unicode.UTF-8 ASCII 我们知道,在计算机内部,所有的信息最终都表示为一个二进制的字符串.每一个二进制位(bit)有0和1两种状态,因此 ...

  5. 在Linux环境下部署MySql服务

    之前有下载部署过几次,但是每次都会踩一些坑.特此记录在liunx下部署安装mysql的基本步骤: 1.卸载老版本的mysql find / -name mysql|xargs rm -rf     查 ...

  6. AtomicReference和AtomicStampedReference

    AtomicReference类提供了一个可以原子读写的对象引用变量. 原子意味着尝试更改相同AtomicReference的多个线程(例如,使用比较和交换操作)不会使AtomicReference最 ...

  7. 面试官:SpringBoot jar 可执行原理,知道吗?

    文章篇幅较长,但是包含了SpringBoot 可执行jar包从头到尾的原理,请读者耐心观看.同时文章是基于 SpringBoot-2.1.3进行分析.涉及的知识点主要包括Maven的生命周期以及自定义 ...

  8. noip2017简要题解。

    重新写了一下去年的题来看看自己到底是有多傻逼. 小凯的疑惑 打表. 时间复杂度 搞了一大坨题面,但是真正有用的信息只有几个: 判断他给你的复杂度是多少. 判断当前循环进不进的去. 判断当前循环产生的贡 ...

  9. shell处理文件内容

    1.head:输出前N行 2.tail:输出后N行 3.cat:查看文件所有内容 4.wc:统计文件内容相关信息(行数,字符数等) 5.

  10. SpringCloud学习系列-构建部门微服务提供者Module

    1.新建microservicecloud-provider-dept-8001 2.POM <project xmlns="http://maven.apache.org/POM/4 ...