分享一个好的学习网站:http://how2j.cn?p=4509

相信大家对spring的配置文件应该都看的很多了,那么大家对配置文件头部的那一坨坨的东西到底是什么了解吗?下面我就把自己的一些见解和大家分享一下:

首先拿一段大家熟悉的头部配置文件来看:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:p="http://www.springframework.org/schema/p"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xmlns:context="http://www.springframework.org/schema/context"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/mvc
  10. http://www.springframework.org/schema/mvc/spring-mvc.xsd
  11. http://www.springframework.org/schema/context
  12. http://www.springframework.org/schema/context/spring-context.xsd">
  13. <!-- 定义controller扫描包 -->
  14. <context:component-scan base-package="com.example.controller" />
  15. <mvc:annotation-driven />
  16. <!-- 处理静态资源 -->
  17. <mvc:default-servlet-handler/>
  18. <!-- 配置视图解析器 -->
  19. <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  20. <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
  21. <property name="prefix" value="/WEB-INF/jsp/"/>
  22. <property name="suffix" value=".jsp"/>
  23. </bean>
  24. </beans>

1.xmlns=http://www.springframework.org/schema/beans  和 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance 是必须有的所有的spring配置文件都一样

2.xmlns:xxx 这个是xml的命名空间,对于命名空间不进行展开,简单的理解其实就是你要使用spring的哪些模块的内容,之所以第一点说xmlns="http://www.springframework.org/schema/beans 是必须的,就是因为beans是spring的根本,如果连这个都没有的话就算不上是spring的配置文件了,在这个配置文件里面还有xmlns:p、 xmlns:mvc、xmlns:context 这三个命名空间,有了这些才可以使用<context:component /> <mvc:annotation-driven /> 这样的功能,如果没有这些命名空间的话而使用<context:component /> <mvc:annotation-driven /> 这些功能是会报错的哦!

3.下面就是xsi:schemaLocation了,这个是用来做什么的呢?其实是为上面配置的命名空间指定xsd规范文件,这样你在进行下面具体配置的时候就会根据这些xsd规范文件给出相应的提示,比如说每个标签是怎么写的,都有些什么属性是都可以智能提示的,以防配置中出错而不太容易排查,在启动服务的时候也会根据xsd规范对配置进行校验。

4.配置文件中.XSD文件的uri是http://www.springframework.org/schema/.............xsd 那么问题来了,真的要到网上去找这个.XSD文件吗?当然不是

打开spring-webmvc-4.2.3.RELEASE.jar>>META-INF>>spring.schemas  会看到以下内容:

http\://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd=org/springframework/web/servlet/config/spring-mvc-3.0.xsd
http\://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd=org/springframework/web/servlet/config/spring-mvc-3.1.xsd
http\://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd=org/springframework/web/servlet/config/spring-mvc-3.2.xsd
http\://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd=org/springframework/web/servlet/config/spring-mvc-4.0.xsd
http\://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd=org/springframework/web/servlet/config/spring-mvc-4.1.xsd
http\://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd=org/springframework/web/servlet/config/spring-mvc-4.2.xsd
http\://www.springframework.org/schema/mvc/spring-mvc.xsd=org/springframework/web/servlet/config/spring-mvc-4.2.xsd

看到这些http://www.springframework.org/schema/.............xsd  内容大家就该明白了,其实http\://www.springframework.org/schema/mvc/spring-mvc.xsd 真正指向的位置是
org/springframework/web/servlet/config/spring-mvc-4.2.xsd,那么打开这个uri看看有什么

果然xsd文件就在这里…………其他的也都是以此类推

转载:http://blog.csdn.net/f_639584391/article/details/50167321

spring配置文件头部配置解析(applicationContext.xml)的更多相关文章

  1. spring配置文件头部配置解析

    http://blog.csdn.net/f_639584391/article/details/50167321

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

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

  3. 玩转Spring Boot 自定义配置、导入XML配置与外部化配置

    玩转Spring Boot 自定义配置.导入XML配置与外部化配置       在这里我会全面介绍在Spring Boot里面如何自定义配置,更改Spring Boot默认的配置,以及介绍各配置的优先 ...

  4. Spring框架找不到 applicationContext.xml文件,可能是由于applicationContext.xml文件的路径没有放在根目录下造成的

    Spring框架找不到 applicationContext.xml文件,可能是由于applicationContext.xml文件的路径没有放在根目录下造成的

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

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

  6. spring或springmvc自动生成applicationcontext.xml或springmvc文件(此文转载和借鉴多篇文章)

    在用spring或者springmvc框架进行开发时,编辑applicationcontext.xml等配置文件是必不可少的,在eclipse中打开applicationcontext.xml通常是这 ...

  7. hibernate3整合spring2时hibernate即用注解又用配置文件情况时spring配置文件的配置写法

    hibernate只用注解时,spring的配置文件的配置如下 <bean id="dataSource" class="org.apache.commons.db ...

  8. spring配置文件中配置sessionFactory失败

    配置失败主要原因有两个: <bean id="studentDaoImp" class="com.gxwuz.maven.dao.StudentDaoImp&quo ...

  9. 当你的Spring IOC 容器(即applicationContext.xml文件)忘记配到web.xml 文件中时

    当你的Spring IOC 容器忘记配到web.xml 文件中时,启动服务器就会报错. 部分错误如下: Caused by: org.springframework.beans.factory.NoS ...

随机推荐

  1. fopen()、fwrite()、fread()函数使用说明与示例

    fopen()函数: 1.作用: 在C语言中fopen()函数用于打开指定路径的文件,获取指向该文件的指针. 2.函数原型: FILE * fopen(const char * path,const  ...

  2. 搞ACM的你伤不起[转载] 原作者:RoBa

    劳资六年前开始搞ACM啊!!!!!!!!!! 从此踏上了尼玛不归路啊!!!!!!!!!!!! 谁特么跟劳资讲算法是程序设计的核心啊!!!!!! 尼玛除了面试题就没见过用算法的地方啊!!!!!! 谁再跟 ...

  3. SQL语句(二十一)—— 触发器(DML触发器)

    触发器 一 .触发器概述(特殊的存储过程) 定义: 在修改指定表值的数据时执行的 存储过程. 不同的是 : 执行存储过程要使用EXEC语句来调用,而触发器的执行不需要使用EXEC语句来调用. 作用: ...

  4. CSS3实战-文字篇

    text-shadow的大作用 多颜色阴影效果,用逗号分隔text-shaodow即可. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tr ...

  5. 【CodeForces】914 F. Substrings in a String bitset

    [题目]F. Substrings in a String [题意]给定小写字母字符串s,支持两种操作:1.修改某个位置的字符,2.给定字符串y,查询区间[l,r]内出现y多少次.|s|,Σ|y|&l ...

  6. Hive笔记之导出查询结果

    一.导出到本地 导出查询结果到本地: INSERT OVERWRITE LOCAL DIRECTORY "/tmp/hive-result/t_visit_video" SELEC ...

  7. 调整扩大VMDK格式VirtualBox磁盘空间

    如果虚拟机的格式是VDI格式的, 那么可以通过这篇文章来调整磁盘大小: 调整Virtual Box硬盘大小 不过楼主当初在创建虚拟机的时候,是用的VMDK格式, 以求与VMWare的兼容性.这时候要扩 ...

  8. 2016.5.57—— Remove Duplicates from Sorted List

    Remove Duplicates from Sorted List 本题收获: 指针: 不管什么指针在定义是就初始化:ListNode *head = NULL; 如果给head指针赋值为第一个no ...

  9. thinkphp报错Call to undefined method app\index\controller\Index::fetch()

    因为要写一个系统,所以又重新下载了thinkphp,然后安装了一下.回忆起这个问题很容易让新手朋友费解.会出现如下报错:Call to undefined method app\index\contr ...

  10. Dummynet模拟高时延网络场景(Windows7)

    如果安装时出现:my_socket failed 2, cannot talk to kernel module 请查看是否以管理员方式运行,如果是,再判断当前操作系统是否为Win7 64位,如果是, ...