分享一个好的学习网站: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. spring IoC容器的实现。

    控制反转是spring的重要概念.而实现控制反转的IoC容器具体又是如何实现呢. IoC容器的目的是能够管理系统中各个对象之间的关系和依赖,为了实现这个功能,spring框架对Bean做了进一步抽象 ...

  2. angularJS $routeProvider

    O'Reilly书上的伪代码 var someModule = angular.module('someModule',[...module dependencies]); someModule.co ...

  3. ASP.NET根据IP获取省市地址

    1.在网站的跟路径下面添加 QQWry.dat 文件,这个文件是IP数据库文件 2.添加以下一个类 IPScanner     C# 代码   复制 public class IPScanner { ...

  4. 20155306 2016-2017-2 《Java程序设计》第6周学习总结

    20155306 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 第十章 输入/输出 10.1 InputStream与OutputStream 如果要将数据 ...

  5. 列表函数&方法

    列表(list)的基本操作,方法及属性.

  6. Django框架下的小人物--Cookie

    1. 什么是Cookie,它的用途是什么? Cookies是一些存储在用户电脑上的小文件.它是被设计用来保存一些站点的用户数据,这样能够让服务器为这样的用户定制内容,后者页面代码能够获取到Cookie ...

  7. NodeJS让前端与后端更友好的分手

    学问   最近“上层建筑”在兴起国学热,所以公司几个月前决定开发一款名叫“学问”的有关于国学的app.     APP的详情页面还是由web来显现具体内容,有些类似于新闻页,图文混排什么的web是最适 ...

  8. Qt多线程编程中的对象线程与函数执行线程

    近来用Qt编写一段多线程的TcpSocket通信程序,被其中Qt中报的几个warning搞晕了,一会儿是说“Cannot create children for a parent that is in ...

  9. transform 动画效果

    http://www.css88.com/tool/css3Preview/Transform.html transform的含义是:改变,使…变形:转换 transform的属性包括:rotate( ...

  10. 对于Json的认识

    Json简介 1. JSON 是什么 JSON,全称是 JavaScript Object Notation,即 JavaScript 对象标记法.   JSON 是一种轻量级(Light-Weigh ...