0044 spring框架的applicationContext.xml的命名空间
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的命名空间的更多相关文章
- Spring 框架的 applicationContext.xml 配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- Spring 框架配置web.xml 整合web struts
package cn.itcast.e_web; import java.io.IOException; import javax.servlet.ServletContext; import jav ...
- 使用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...”. 原 ...
- Spring的配置文件ApplicationContext.xml配置头文件解析
Spring的配置文件ApplicationContext.xml配置头文件解析 原创 2016年12月16日 14:22:43 标签: spring配置文件 5446 spring中的applica ...
- Spring框架配置beans.xml扩展
Spring学习笔记(二) 续Spring 学习笔记(一)之后,对Spring框架XML的操作进行整理 1 什么是IOC(DI) IOC = inversion of control 控制反转 D ...
- Spring框架配置beans.xml
Spring学习笔记(一) 一.Spring 框架 Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.框架的主要优势之一就是其分层架构,分层架构允许您选择使用哪一个组件,同时为 ...
- 【转载】Spring中的applicationContext.xml与SpringMVC的xxx-servlet.xml的区别
一直搞不明白两者的区别. 如果使用了SpringMVC,事实上,bean的配置完全可以在xxx-servlet.xml中进行配置.为什么需要applicationContext.xml?一定必须? 一 ...
- Spring中,applicationContext.xml 配置文件在web.xml中的配置详解
一.首先写一下代码结构. 二.再看web.xml中的配置情况. <?xml version="1.0" encoding="UTF-8"?> < ...
- 【Spring学习笔记-3.1】让bean获取spring容器上下文(applicationContext.xml)
*.hl_mark_KMSmartTagPinkImg{background-color:#ffaaff;}*.hl_mark_KMSmartTagBlueImg{background-color:# ...
随机推荐
- @MySQL为表字段添加索引
删除索引~ DROP INDEX `idx_dict_type` ON `article` 1.添加PRIMARY KEY(主键索引): ALTER TABLE `table_name` ADD PR ...
- [转]SQLServer和Oracle,存储过程区别,常用函数对比
本文转自:http://www.cnblogs.com/neru/archive/2011/08/18/2144049.html 以前一直用sqlserver,只有很少的一点oracle的经验,现在要 ...
- 对自助提卡系统EDLM的一次代码审计
前言 并非有意愿要审计该站,前面的走的黑盒没有过于精彩部分就不在贴上了,对于此系统站你们懂的,多说无益,这套程序是开源的,像这种自助提卡系统相信大家已经不在陌生了,很多违法网站通过这种平台方式提卡密的 ...
- NDK下vfork+execl启动程序
pid_t _pid = vfork(); if (_pid == 0) {//child process LOGV("[ContextSharing]in child process.&q ...
- NDK下IPC问题
由于AllJoyn的join session timeout问题一直无法解决,我们怀疑AllJoyn有些内部变量没有清理干净,因此考虑将AllJoyn相关功能放到一个单独的进程中,一旦join ses ...
- phpcms 后台验证码不显示date() expects parameter 2 to be long
方法一: 主要在于是否开启gd库 查看办法 找到php.ini文件 搜索extension=php_gd2.dll这段代码 然后把前面的;符号去掉即可. 方法二: 关键一点是获取验证码的图片与全局变量 ...
- 极光推送sdk使用
创建应用 进入极光控制台后,点击“创建应用”按钮,进入创建应用的界面. 填上你的应用程序的名称以及应用包名这二项就可以了, 最后点击最下方的 “创建我的应用”按钮,创建应用完毕. 创建应用 填 ...
- DNS使用的是TCP协议还是UDP协议简析
DNS使用的是TCP协议还是UDP协议简析 DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP栈也算是个另类.但很少有人知道DNS分别在什么情况 ...
- Vue 组件通信(组件间通信)
1.中央事件总线bus <!DOCTYPE html> <html lang="zh"> <head> <meta charset=&qu ...
- JAVA小项目实例源码—学习娱乐小助手
代码地址如下:http://www.demodashi.com/demo/11456.html 一.程序实现 项目目录: MyJFrame:实现项目界面样式: AppProcess:实现调用api或爬 ...