在spring的配置中,总能看见以下的代码:spring
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" default-autowire="byName">spring-mvc
刚开始的时候也只是似懂非懂的照搬照用,而后去研究了一下 首先: 1.beans —— xml文件的根节点 2.xmlns ——是XML NameSpace的缩写,由于XML文件的标签名称都是自定义的,本身写的和其余人定义的标签颇有可能会重复命名,而功能却不同,因此须要加上一个namespace来区分这个xml文件和其余的xml文件,相似于Java中的package。 3.xmlns:xsi ——是指xml文件遵照xml规范,xsi全名:xml schema instance,是指具体用到的schema资源文件里定义的元素所准守的规范。即http://www.w3.org/2001/XMLSchema-instance这个文件里定义的元素遵照什么标准 4.xsi:schemaLocation——是指本文档里的xml元素所遵照的规范,这些规范都是由官方制定的,能够进你写的网址里面看版本的变更。xsd的网址还能够帮助你判断使用的代码是否合法。 因此以下代码:mvc
<!-- 启用spring mvc 注解 -->app
<context:annotation-config/> <!--自动扫描--> <context:component-scan base-package="com.icekredit.credit.controller"/> <context:component-scan base-package="com.icekredit.credit.service.impl"/> <!--自动配置注解映射器和适配器--> <mvc:annotation-driven /> <mvc:default-servlet-handler /> <mvc:resources location="/static/" mapping="/static/**" />
代码里面用到了< mvc >的标签就要先引入spa
xmlns:mvc="http://www.springframework.org/schema/mvc"代码规范
而后须要遵照的代码规范有:code
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsdcomponent