spring設定檔頭部配置解析(applicationContext.xml)

來源:互聯網
上載者:User

標籤:default   mvc   jar   圖解   name   必須   就是   3.2   lan   

分享一個好的學習網站:http://how2j.cn?p=4509     

相信大家對spring的設定檔應該都看的很多了,那麼大家對設定檔頭部的那一坨坨的東西到底是什麼瞭解嗎?下面我就把自己的一些見解和大家分享一下:

首先拿一段大家熟悉的頭部設定檔來看:

 

[html] view plain copy 
  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.       
  14.     <!-- 定義controller掃描包 -->  
  15.     <context:component-scan base-package="com.example.controller" />  
  16.     <mvc:annotation-driven />  
  17.     <!-- 處理靜態資源 -->  
  18.     <mvc:default-servlet-handler/>  
  19.     <!-- 配置視圖解析器 -->  
  20.     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  21.        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>  
  22.        <property name="prefix" value="/WEB-INF/jsp/"/>  
  23.        <property name="suffix" value=".jsp"/>  
  24.     </bean>  
  25.       
  26. </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)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.