Spring框架中,创建bean,装配bean,事务控制等,可以用xml配置或者注解扫描的方法实现。如果用注解扫描,在xml配置中得加上

<context:component-scan base-package="XXX" />
<mvc:annotation-driven />
<tx:annotation-driven transaction-manager="XXX" />

但以上配置生效的前提,还要配置好相应的命名空间,比如:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd ">
。。。
</beans>

那这些命名空间又是什么,以tx为例:

xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd "

『xmlns:tx="http://www.springframework.org/schema/tx"』声明了一个命名空间,tx就代表了『http://www.springframework.org/schema/tx』,后者看起来像个url,其实只是个字符串,之所以写成url的样子,只是为了确保唯一,就类似于包名要用域名的反写+项目名+模块名一样

『xsi:schemaLocation="http://www.springframework.org/schema/tx【空格】http://www.springframework.org/schema/tx/spring-tx-4.0.xsd "』指定了用于解析和校验xml文件的xsd文件的位置,那如何找到这个xsd文件呢

把tx.jar解压缩后,在META-INF目录下有一个spring.schemas文件,打开后如下所示:

http\://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd
http\://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd
http\://www.springframework.org/schema/tx/spring-tx-3.0.xsd=org/springframework/transaction/config/spring-tx-3.0.xsd
http\://www.springframework.org/schema/tx/spring-tx-3.1.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd
http\://www.springframework.org/schema/tx/spring-tx-3.2.xsd=org/springframework/transaction/config/spring-tx-3.2.xsd
http\://www.springframework.org/schema/tx/spring-tx-4.0.xsd=org/springframework/transaction/config/spring-tx-4.0.xsd
http\://www.springframework.org/schema/tx/spring-tx-4.1.xsd=org/springframework/transaction/config/spring-tx-4.1.xsd
http\://www.springframework.org/schema/tx/spring-tx-4.2.xsd=org/springframework/transaction/config/spring-tx-4.2.xsd
http\://www.springframework.org/schema/tx/spring-tx-4.3.xsd=org/springframework/transaction/config/spring-tx-4.3.xsd
http\://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-4.3.xsd

这里有xsd文件的位置的名称跟具体xsd文件所在目录的映射,到『org/springframework/transaction/config/』目录下就可以找到对应的xsd文件,打开后基本如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<xsd:schema xmlns="http://www.springframework.org/schema/tx"    <!-- 与上面的xmlns:tx的值相同 -->
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/tx"
elementFormDefault="qualified"
attributeFormDefault="unqualified"> <xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"/>
<xsd:import namespace="http://www.springframework.org/schema/tool" schemaLocation="http://www.springframework.org/schema/tool/spring-tool-4.0.xsd"/> <xsd:annotation>
.................
</xsd:annotation> <xsd:element name="advice"> <!-- 引入这个命名空间后,才能用<tx:advice><tx:annotation-driven>等 -->
.................
</xsd:element> <xsd:element name="annotation-driven">
.................
</xsd:element> <xsd:element name="jta-transaction-manager">
.................
</xsd:complexType> </xsd:schema>

如何引入一个命名空间呢?

1. 声明:xmlns:tx="命名空间" 这里命名空间跟xsd文件的xmlns的值相同

2. 在xsi:schemaLocation指定xsd文件的位置:命名空间【空格】config目录下的.schemas的映射

0044 spring框架的applicationContext.xml的命名空间的更多相关文章

  1. Spring 框架的 applicationContext.xml 配置文件

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  2. Spring 框架配置web.xml 整合web struts

    package cn.itcast.e_web; import java.io.IOException; import javax.servlet.ServletContext; import jav ...

  3. 使用spring框架,用xml方式进行bean装配出现“The fully qualified name of the bean's class, except if it serves...”

    使用spring框架,用xml方式进行bean装配出现“The fully qualified name of the bean's class, except if it serves...”. 原 ...

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

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

  5. Spring框架配置beans.xml扩展

    Spring学习笔记(二) 续Spring 学习笔记(一)之后,对Spring框架XML的操作进行整理 1 什么是IOC(DI) IOC = inversion of control   控制反转 D ...

  6. Spring框架配置beans.xml

    Spring学习笔记(一) 一.Spring 框架 Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.框架的主要优势之一就是其分层架构,分层架构允许您选择使用哪一个组件,同时为 ...

  7. 【转载】Spring中的applicationContext.xml与SpringMVC的xxx-servlet.xml的区别

    一直搞不明白两者的区别. 如果使用了SpringMVC,事实上,bean的配置完全可以在xxx-servlet.xml中进行配置.为什么需要applicationContext.xml?一定必须? 一 ...

  8. Spring中,applicationContext.xml 配置文件在web.xml中的配置详解

    一.首先写一下代码结构. 二.再看web.xml中的配置情况. <?xml version="1.0" encoding="UTF-8"?> < ...

  9. 【Spring学习笔记-3.1】让bean获取spring容器上下文(applicationContext.xml)

    *.hl_mark_KMSmartTagPinkImg{background-color:#ffaaff;}*.hl_mark_KMSmartTagBlueImg{background-color:# ...

随机推荐

  1. 靠谱助手 http://www.kpzs.com/

    靠谱助手 http://www.kpzs.com/ 靠谱助手是于2013年5月18日推出的一个专为第三方智能安卓引擎提供管理的免费应用程序,是国内最完美的PC端管理软件. 安卓引擎支持微信.陌陌等日常 ...

  2. python logging模块用法

    http://blog.csdn.net/zyz511919766/article/details/25136485/ import logging logging.debug('debug mess ...

  3. [转]Sql server 大数据量分页存储过程效率测试附代码

    本文转自:http://www.cnblogs.com/lli0077/archive/2008/09/03/1282862.html 在项目中,我们经常遇到或用到分页,那么在大数据量(百万级以上)下 ...

  4. ExtJS初学笔记---Ext.Msg.alert无效果

    最近开始学ExtJS,书上的第一个例子是: 1 2 3 Ext.onReady(function(){     Ext.Msg.alert('Hello.', 'Hello'); }); 这个是Ext ...

  5. http://blog.csdn.net/xingfuzhijianxia/article/details/6433918

    http://blog.csdn.net/xingfuzhijianxia/article/details/6433918

  6. Log文件太大,手机ROM空间被占满

    客户要装车,进行项目验收了. 今天拿着几台手机去客户处,其中有一台手机从昨天晚上开始就一直开着我们的APP,今天早晨打开手机发现APP没有反应了. 在程序列表中将其杀掉,然后再启动程序,发现程序不能启 ...

  7. js 倒计时跳转页面

    <script type="text/javascript">var i = 5; var intervalid; intervalid = setInterval(& ...

  8. windows Visual Studio 2017 编译 HEVC cmake-3.8.1-win64-x64.msi 下载

    ttps://github.com/OpenHEVC/openHEVC 下载一 直接下载源码(可选)或下载源码包,我这里下载的是源码 打开 Visual Studio () 去 github 找到源码 ...

  9. JAVA基础(9)——容器(3)——并发容器

    转载:http://blog.csdn.net/weitry/article/details/52964509 JAVA基础系列规划: JAVA基础(1)——基本概念 JAVA基础(2)——数据类型 ...

  10. spring-boot 集成 swagger 问题的解决

    spring-boot 集成 swagger 网上有许多关于 spring boot 集成 swagger 的教程.按照教程去做,发现无法打开接口界面. 项目由 spring mvc 迁移过来,是一个 ...