spring xml頭文件xmlns和xsi的意思

在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

相關文章
相關標籤/搜索