关于spring配置文件的头部编写
//普通spring配置文件模板
1 <?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> </beans>
//添加注解后的模板格式
<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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd">
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
这是spring配置文件必须的部分。
第1行:声明xml文件默认的命名空间,表示未使用其他命名空间的所有标签的默认命名空间。<bean id="" ></bean>默认命名空间,不需要加前缀<bean:bean id="">.
第2行:声明XML Schema 实例,声明后就可以使用 schemaLocation 属性了。
xmlns:aop="http://www.springframework.org/schema/aop"
这个就是spring配置文件里面需要使用到aop的标签,声明前缀为aop的命名空间,后面的URL用于标示命名空间的地址不会被解析器用于查找信息。其惟一的作用是赋予命名空间一个惟一的名称。当命名空间被定义在元素的开始标签中时,所有带有相同前缀的子元素都会与同一个命名空间相关联。然后其他比如context(针对组件标签)、MVC(针对mvc标签)、tx(针对事务标签)都一样的意思。
xsi:schemaLaction部分:
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
是为上面配置的命名空间指定xsd规范文件,这样你在进行下面具体配置的时候就会根据这些xsd规范文件给出相应的提示,比如说每个标签是怎么写的,都有些什么属性是都可以智能提示的,以防配置中出错而不太容易排查,在启动服务的时候也会根据xsd规范对配置进行校验。但是这里需要为你上面xmlns里面配置的mvc、aop、tx等都配置上xsd规范文件。
------------------------------------------------------------------------------------------------------
【xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd】
指定了具体版本,自己写的时候怎么知道用哪个版本?
在每个xsi:schemaLocation属性中,都是一个具有指定版本号的xsd文件,而对于没有加版本号的问题,是由于使用了默认值,实质上这个默认值是有一个具体的版本号的。当然,你也可以使用具体的版本号。
而对于这些xsd文件的路径查找的方法,可以定位到每一个jar包去找,比如使用了4.1.4版本beans的jar包,那么可以通过Eclipse打开spring-beans-4.1.4.RELEASE.jar文件,并打开META-INF/spring.schemas文件,如下所示:


可以看出,默认的地址上也是制定了具体的版本号的,那么根据后面的地址打开org/springframework/beans/factory/xml目录,如下所示:

可以看出最后会来这里定位xsd文件,从而实现标签的提示。
总结:
XML Schema命名空间避免命名冲突,就像Java中的package一样,将不同作用的标签分门别类(比如Spring中的tx命名空间针对事务类的标签,context命名空间针对组件的标签)。
参考:
https://www.cnblogs.com/EasonJim/p/6880329.html
关于spring配置文件的头部编写的更多相关文章
- spring 配置文件的头部 xmls
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...
- 【深入JAVA EE】Spring配置文件解析
在阅读的过程中有不论什么问题,欢迎一起交流 邮箱:1494713801@qq.com QQ:1494713801 一.Spring头信息 Spring配置文件的头部信息通常是固定不变的.但每个标 ...
- Spring配置文件头及xsd文件版本
最初Spring配置文件的头部声明如下: Xml代码 <?xml version="1.0" encoding="UTF-8"?> <!D ...
- Spring配置文件beans.xml头部配置解释
Spring配置文件beans.xml头部配置解释 - EasonJim - 博客园https://www.cnblogs.com/EasonJim/p/6880329.html
- SpringMVC 学习 九 SSM环境搭建 (二) Spring配置文件的编写
spring配置文件中需要干的事情 (一)开启 Service与pojo包的注解扫描 注意:spring 扫描与表对应的实体类,以及service层的类,不能用来扫描Controller层的类,因为 ...
- spring配置文件头部配置解析(applicationContext.xml)
分享一个好的学习网站:http://how2j.cn?p=4509 相信大家对spring的配置文件应该都看的很多了,那么大家对配置文件头部的那一坨坨的东西到底是什么了解吗?下面我就把自己的一些见解和 ...
- Spring配置文件中未引入dubbo命名空间头部配置而引起的错误案例
问题描述: Spring配置文件中未引入dubbo命名空间的头部配置而引起项目启动时报出如下错误信息: org.springframework.beans.factory.xml.XmlBeanDef ...
- Spring 配置文件头部xmls解析
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...
- spring配置文件头部xmlns配置精髓
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...
随机推荐
- js原生带缩略图的图片切换效果
js原生带缩略图的图片切换效果 本例中用到的 moveElement(elementID,final_x,final_y,interval)是来自<JavaScript DOM编程艺术(中文第二 ...
- Hibernate (ORM)
1 框架体系结构 2 hibernate入门 2.1 ORM框架 Hibernate是一个数据持久化层的ORM框架. Object:对象,java对象,此处特指JavaBean Relational: ...
- 轻松看懂机器学习十大常用算法 (Machine Learning Top 10 Commonly Used Algorithms)
原文出处: 不会停的蜗牛 通过本篇文章可以对ML的常用算法有个常识性的认识,没有代码,没有复杂的理论推导,就是图解一下,知道这些算法是什么,它们是怎么应用的,例子主要是分类问题. 每个算法都看了 ...
- C# 修改GroupBox的边框颜色和字体颜色
改变GroupBox边框和的颜色 private void groupBox_BasicInformation_Paint(object sender, PaintEventArgs e) { e.G ...
- php遍历数组赋值
<?php $arr=array( array("num"=>100,"name"=>"Liuxy","scor ...
- 密码存储中MD5的安全问题与替代方案
md5安全吗?有多么地不安全?如何才能安全地存储密码?... md5安全吗? 经过各种安全事件后,很多系统在存放密码的时候不会直接存放明文密码了,大都改成了存放了 md5 加密(hash)后的密码,可 ...
- Linux系统学习之系统启动的5个过程
Linux 系统启动过程 Linux系统的启动过程可以分为5个阶段: 1. 内核引导 当计算机打开电源后,首先是BIOS开机自检,按照BIOS中设置的启动设备(通常是硬盘)来启动.操作系统接管硬件以后 ...
- Day01——Python简介
一.Python简介 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC ...
- 四、CentOS 安装mariadb——Linux学习笔记
A)安装及配置 下载mariadb: yum -y install mariadb-server mariadb 开启mariadb服务: systemctl start mariadb.servic ...
- 使用Powershell 管理 Windows 2012 hyper-v复制
HyperV复制相关命令 Suspend-VMReplication Suspends replication of a virtual machine. 暂停复制虚拟机. Resume-VMRepl ...