首页 > 编程语言 > 详细

spring配置文件头部配置解析

时间:2017-04-07 01:21:07      阅读:262      评论:0      收藏:0      [点我收藏+]

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:aop="http://www.springframework.org/schema/aop"
 6         xmlns:tx="http://www.springframework.org/schema/tx"
 7         xmlns:context="http://www.springframework.org/schema/context"
 8         xsi:schemaLocation="http://www.springframework.org/schema/beans 
 9                             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
10                             http://www.springframework.org/schema/aop     
11                             http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   
12                             http://www.springframework.org/schema/tx
13                             http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
14                             http://www.springframework.org/schema/context     
15                             http://www.springframework.org/schema/context/spring-context-3.0.xsd">
16     <!-- HandlerMapping -->  
17     <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/> 
18     <!-- HandlerAdapter -->  
19     <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
20     <!-- ViewResolver --> 
21     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
22         <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
23         <property name="prefix" value="/WEB-INF/jsp/"/>
24         <property name="suffix" value=".jsp"/>
25     </bean>
26     <!-- 处理器 -->  
27     <bean name="/hello" class="cn.javass.chapter2.web.controller.HelloWorldController"/>
28 </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文件就在这里…………其他的也都是以此类推.

spring配置文件头部配置解析

原文:http://www.cnblogs.com/wqfeng-2017/p/6675955.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!