spring配置文件头部配置解析
2015-12-03 22:35
363 查看
最近由于公司的项目用springmvc,所以自己也必须学习了,相信大家对spring的配置文件应该都看的很多了,那么大家对配置文件头部的那一坨坨的东西到底是什么了解吗?下面我就把自己的一些见解和大家分享一下:
首先拿一段大家熟悉的头部配置文件来看:
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文件保存下来,然后以后再用的时候直接复制过来就好!
就写到这里了,希望可以帮到刚刚学习spring的朋友!!
首先拿一段大家熟悉的头部配置文件来看:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 定义controller扫描包 --> <context:component-scan base-package="com.example.controller" /> <mvc:annotation-driven /> <!-- 处理静态资源 --> <mvc:default-servlet-handler/> <!-- 配置视图解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </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文件保存下来,然后以后再用的时候直接复制过来就好!
就写到这里了,希望可以帮到刚刚学习spring的朋友!!
相关文章推荐
- Spring/Aop代码总结
- mybatis实战教程之五:与spring3集成
- java中实现类似函数指针的功能
- Java分页
- 在MAC下面用 eclipse调试android 6.0 framework
- [置顶] struts2笔试面试
- java总结
- java实现字符串的逆向输出——单词保持原样和单词也逆向输出
- java编译的莫名奇妙问题总结
- 自己写的基于java Annotation(注解)的数据校验框架
- Eclipse用Maven打包后,JUnit老报ClassNotFound错误
- LeetCode 299 : Bulls and Cows (Java)
- 生产环境JAVA进程高CPU占用故障排查
- Eclipse 代码提示功能设置
- Java多线程初学笔记
- JAVA图形界面三星题之Hangman
- [转]JAVA设计模式之单例模式
- eclipse的maven、Scala环境搭建
- 浅谈面向对象(java)
- Java Web中的中文编码问题(上)