1. 程式人生 > >Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd'問題解決方法

Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd'問題解決方法

我們公司使了阿里的dubbo,但是阿里的開源網站http://code.alibabatech.com,掛掉有好幾個月了,為什麼我們的應用啟動沒有問題?

我們的應用的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" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
      
  4.     xsi:schemaLocation="http://www.springframework.org/schema/beans  
  5.             http://www.springframework.org/schema/beans/spring-beans.xsd  
  6.             http://code.alibabatech.com/schema/dubbo  
  7.             http://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
我們都知道Spring在啟動時是要檢驗XML檔案的。或者為什麼在Eclipse裡xml沒有錯誤提示?

比如這樣的一個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.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">  
  5. </beans>
      
我們也可以在後面加上版本號:
  1. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">  
有這個版本號和沒有有什麼區別呢?

XML的一些概念

首先來看下xml的一些概念:

xml的schema裡有namespace,可以給它起個別名。比如常見的spring的namespace:

  1. xmlns:mvc="http://www.springframework.org/schema/mvc"  
  2. xmlns:context="http://www.springframework.org/schema/context"  
通常情況下,namespace對應的URI是一個存放XSD的地址,儘管規範沒有這麼要求。如果沒有提供schemaLocation,那麼Spring的XML解析器會從namespace的URI里加載XSD檔案。我們可以把配置檔案改成這個樣子,也是可以正常工作的:
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans/spring-beans.xsd"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
schemaLocation提供了一個xml namespace到對應的XSD檔案的一個對映,所以我們可以看到,在xsi:schemaLocation後面配置的字串都是成對的,前面的是namespace的URI,後面是xsd檔案的URI。比如:
  1. xsi:schemaLocation="http://www.springframework.org/schema/beans  
  2. http://www.springframework.org/schema/beans/spring-beans.xsd  
  3. http://www.springframework.org/schema/security  
  4. http://www.springframework.org/schema/security/spring-security.xsd"  

Spring是如何校驗XML的

Spring預設在啟動時是要載入XSD檔案來驗證xml檔案的,所以如果有的時候斷網了,或者一些開源軟體切換域名,那麼就很容易碰到應用啟動不了。我記得當時Oracle收購Sun公司時,遇到過這個情況。

為了防止這種情況,Spring提供了一種機制,預設從本地載入XSD檔案。開啟spring-context-3.2.0.RELEASE.jar,可以看到裡面有兩個特別的檔案:

spring.handlers

  1. http\://www.springframework.org/schema/context=org.springframework.context.config.ContextNamespaceHandler  
  2. http\://www.springframework.org/schema/jee=org.springframework.ejb.config.JeeNamespaceHandler  
  3. http\://www.springframework.org/schema/lang=org.springframework.scripting.config.LangNamespaceHandler  
  4. http\://www.springframework.org/schema/task=org.springframework.scheduling.config.TaskNamespaceHandler  
  5. http\://www.springframework.org/schema/cache=org.springframework.cache.config.CacheNamespaceHandler  

spring.schemas

  1. http\://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd  
  2. http\://www.springframework.org/schema/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd  
  3. http\://www.springframework.org/schema/context/spring-context-3.1.xsd=org/springframework/context/config/spring-context-3.1.xsd  
  4. http\://www.springframework.org/schema/context/spring-context-3.2.xsd=org/springframework/context/config/spring-context-3.2.xsd  
  5. http\://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.2.xsd  
  6. ...  
再開啟jar包裡的org/springframework/context/config/ 目錄,可以看到下面有

spring-context-2.5.xsd
spring-context-3.0.xsd
spring-context-3.1.xsd
spring-context-3.2.xsd

很明顯,可以想到Spring是把XSD檔案放到本地了,再在spring.schemas裡做了一個對映,優先從本地裡載入XSD檔案。

並且Spring很貼心,把舊版本的XSD檔案也全放了。這樣可以防止升級了Spring版本,而配置檔案裡用的還是舊版本的XSD檔案,然後斷網了,應用啟動不了。

我們還可以看到,在沒有配置版本號時,用的就是當前版本的XSD檔案:

  1. http\://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.2.xsd  
同樣,我們開啟dubbo的jar包,可以在它的spring.schemas檔案裡看到有這樣的配置:
  1. http\://code.alibabatech.com/schema/dubbo/dubbo.xsd=META-INF/dubbo.xsd  

所以,Spring在載入dubbo時,會從dubbo的jar里加載dubbo.xsd。

雖然啟動沒有問題,但xml驗證Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd'出錯,這個問題如何解決呢?

可以通過eclipse 手動新增schema檔案來解決這個問題,如圖:




配置成功後,右擊applicationContext-dubbo.xml選擇validate,進行xml重新驗證即可。

參考文章:

http://blog.csdn.net/kenchow126/article/details/8513824

http://blog.csdn.net/hengyunabc/article/details/22295749

相關推薦

Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd'問題解決方法

我們公司使了阿里的dubbo,但是阿里的開源網站http://code.alibabatech.com,掛掉有好幾個月了,為什麼我們的應用啟動沒有問題? 我們的應用的Spring配置檔案裡有類似的配置: <?xml version="1.0" encoding

dubbo使用過程中報錯:Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd',

一、出錯原因:http://code.alibabatech.com/schema/dubbo/該地址已經失效 二、解決辦法:在專案內部配置 2.1、 根據自己jar包下載位置找到jar包:dubbo

Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd'

Multiple annotations found at this line:- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'dub

無法讀取方案文件 'http://code.alibabatech.com/schema/dubbo因為 1) 無法找到文件; 2) 無法讀取文件; 3)

現象: application.xml 文件不報錯,但是執行程式,會報錯,dubbo.xsd  引用的是dubbo.2.4.9.jar ;分析: 網上有人說是dubbo jar版本的問題,後來我換了版本之後還是不行,後來分析發現,程式執行的時候找不到dubbo.jar 解決辦

配置Dubbo Demo遇到的坑之二---無法讀取方案文件 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd'

錯誤資訊如圖所示,我用的是網上下的Dubbo 入門Demo,執行時遇到這個問題,按照網上說的設定本地dubbo.xsd檔案之後依舊報出該錯誤。在經過一晚上的瞎雞巴亂弄之後終於解決了。下載的Demo使用的Dubbo是2.5.3版本,我將版本號換成2.6.0之後解決了問題修改之前

dubbo配置檔案報錯schema_reference.4: Failed to read schema document ...

Multiple annotations found at this line: - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for e

Spring如何載入XSD檔案(org.xml.sax.SAXParseException: Failed to read schema document錯誤的解決方法)

有時候你會發現過去一直啟動正常的系統,某天啟動時會報出形如下面的錯誤: org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.spr

【常用積累】xml檔案中,出現Failed to read schema document問題解決

    專案匯入到新的環境或者開發工具當中時,有時xml檔案出現了Failed to read ***.xsd檔案的錯誤,這種宣告類檔案,通常在解析xml檔案過程中,按順序載入。載入過程中,根據xml檔案給定的url路徑,進行下載。但這種xsd宣告檔案,並不都是從網上下載的,

spring boot 報錯 Failed to read HTTP message

2008-12-13 15:06:03,930 WARN (DefaultHandlerExceptionResolver.java:384)- Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotRead

Failed to read artifact descriptor for xxx:jar 的Maven項目jar包依賴配置的問題解決

描述 tin ava 打開 文件 我們 記事本 last .com 在開發的過程中,尤其是新手,我們經常遇到Maven下載依賴jar包的問題,也就是遇到“Failed to read artifact descriptor for xxx:jar”的

Eclipse4.6安裝Tomcat插件時報錯:Unable to read repository at http://tomcatplugin.sf.net/update/content.xml. Received fatal alert: handshake_failure

logs tomcat repos cef blog 時報 技術分享 src tom 錯誤如下: Unable to read repository at http://tomcatplugin.sf.net/update/content.xml.Received fat

artifactdescriptorexception:Failed to read artifact descriptor for xxx:jar ”

eas date 下載 解決 upd cep snap ots exceptio 在Eclipse中執行Maven的install命令時,報“Failed to read artifact descriptor for xxx:jar ”的錯誤。這可能是在下載過程中文件出現

Failed to read candidate component class: URL [];

異常異常信息: Failed to read candidate component class: URL []; nested exception is java.lang.IllegalArgumentException 異常原因: 版本問題:spring 3.2 不支持 jdk 1.8 編譯環境。

Failed to initialize component [Connector[HTTP/1.1-8086]]

acc 1.0 但是 frame await ESS .org pause check 嚴重: Failed to initialize end point associated with ProtocolHandler ["http-apr

maven報Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6的解決方案

man 一個 art enc resources osi pre read 是我 上面截圖是我在新建maven項目的時候報錯信息提示,我是這麽解決的 1.在pom.xml文件中加入maven-resources-plugin配置 <dependency>

apache2啟動失敗(Failed to start The Apache HTTP Server.)解決方案

star 卸載 sta 啟動 art code led sudo pac 不知道如何啟動apache2就啟動不來了。 如下圖所示: 即使卸載了重新裝也是如此 經過測試卸載並清除軟件包的配置即可解決   sudo apt-get purge apache2   s

maven 本地倉庫存在jar包但是專案依舊提示 Failed to read artifact XXX missing artifact XXX的問題

今天從svn匯入一個專案後缺少一個org.restlet.2.1.2.jar 的jar包,而且用無法從官網下載下來,每次update project 後只下載一些 .lastupdate 字尾的檔案。無奈只能自己手動下載jar包到倉庫。下載下來後重新update project 還是會報錯(如題),

【Error】gdb.attach錯誤 Failed to read a valid object file image from memory.

python指令碼中pwntools gdb.attach遇到錯誤:Failed to read a valid object file image from memory. ****** Your encoding (ANSI_X3.4-1968) is different than UT

Failed to read artifact descriptor--maven問題總結

在開發的過程中,作為新手,經常遇到Maven下載依賴的時候,"Failed to read artifact descriptor for xxx:jar"的錯誤 對於這種非業務相關的問題,耽誤時間非常不效率,看到網站很多博文,思路大概是這樣的 思路1: 刪除倉庫內對應依賴的資料夾

BeanDefinitionStoreException Failed to read candidate component class

up vote down vote favoriteCan someone tell me how to solve this issue?