//普通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配置文件的头部编写的更多相关文章

  1. spring 配置文件的头部 xmls

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...

  2. 【深入JAVA EE】Spring配置文件解析

    在阅读的过程中有不论什么问题,欢迎一起交流 邮箱:1494713801@qq.com    QQ:1494713801 一.Spring头信息 Spring配置文件的头部信息通常是固定不变的.但每个标 ...

  3. Spring配置文件头及xsd文件版本

    最初Spring配置文件的头部声明如下: Xml代码   <?xml version="1.0" encoding="UTF-8"?> <!D ...

  4. Spring配置文件beans.xml头部配置解释

    Spring配置文件beans.xml头部配置解释 - EasonJim - 博客园https://www.cnblogs.com/EasonJim/p/6880329.html

  5. SpringMVC 学习 九 SSM环境搭建 (二) Spring配置文件的编写

    spring配置文件中需要干的事情 (一)开启  Service与pojo包的注解扫描 注意:spring 扫描与表对应的实体类,以及service层的类,不能用来扫描Controller层的类,因为 ...

  6. spring配置文件头部配置解析(applicationContext.xml)

    分享一个好的学习网站:http://how2j.cn?p=4509 相信大家对spring的配置文件应该都看的很多了,那么大家对配置文件头部的那一坨坨的东西到底是什么了解吗?下面我就把自己的一些见解和 ...

  7. Spring配置文件中未引入dubbo命名空间头部配置而引起的错误案例

    问题描述: Spring配置文件中未引入dubbo命名空间的头部配置而引起项目启动时报出如下错误信息: org.springframework.beans.factory.xml.XmlBeanDef ...

  8. Spring 配置文件头部xmls解析

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...

  9. spring配置文件头部xmlns配置精髓

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...

随机推荐

  1. 关于开发Cesium造成的电脑风扇狂飙的问题

    最近在开发Cesium的项目,每次一打开浏览器渲染3D 模型.风扇就狂飙起来,进任务管理器查看发现集显使用率100%,独显使用率0%.使用的是集显进行渲染.怪不得风扇会飙起来.既然知道问题所在,解决的 ...

  2. html简介(自己理解和老师讲课)

    首先讲开发网页三种技术:html,css,javascript.html负责网页的结构,css站在没学角度对网页进行美化,javascript负责网页交互,站在用户体验角度设计网页交互效果 而我们所学 ...

  3. MySQL数据库(5)----删除或更新已有行

    有时候,会需要删除某些行,或者修改其内容.这是候便需要用到DELETE语句和UPDATE语句. 1. DELETE 语句的基本格式如下所示: DELETE FROM tbl_name WHERE wh ...

  4. 基础架构之Docker私有库

    由于项目要容器化,所有搭建自己的镜像库也是很有必要的,不然发到直接使用官方的镜像库,速度绝对能让你头疼,这篇文章就介绍搭建自己的镜像私有库. (一)  环境要求 Centos 7.5.1804 Doc ...

  5. Data truncation: Out of range value for column 'id' at row 1 ### The

    org.springframework.dao.DataIntegrityViolationException: ### Error updating database. Cause: com.mys ...

  6. 红黑树(R-B Tree)

    R-B Tree简介 R-B Tree,全称是Red-Black Tree,又称为“红黑树”,它一种特殊的二叉查找树.红黑树的每个节点上都有存储位表示节点的颜色,可以是红(Red)或黑(Black). ...

  7. l2tp over ipsec

    搭建教程: 转自: https://segmentfault.com/a/1190000006125737 http://www.wangyuxiong.com/blog/ti-yan-qiang-w ...

  8. MyEcplise使用---使用 MyEclipse 反转引擎生成数据库

    使用 MyEclipse 反转引擎,生成数据库 步骤: 1. 新建 Database 连接 2. 新建web项目 temp 添加myeclipse hibernate 能力 3. Hibernate ...

  9. 启动入口Start.java分析

    框架的启动器在包:org.ofbiz.base.start 入口为:Start.java的main方法 Start.java启动器内容: 步骤 详情 入参校验 help/status/shutdown ...

  10. JSP的重定向有两种forward和sendRedirect

    jsp:forward重定向 当index.jsp存放在tomcat服务器应用目录下时:D:\Tomcat 7.0\webapps\Spring_shizhan4ban_Chapter05\index ...