【Dubbo&&Zookeeper】3、Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd'问题解决方法
转自:http://blog.csdn.net/gaoshanliushui2009/article/details/50469595
我们公司使了阿里的dubbo,但是阿里的开源网站http://code.alibabatech.com,挂掉有好几个月了,为什么我们的应用启动没有问题?
我们的应用的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:dubbo="http://code.alibabatech.com/schema/dubbo"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://code.alibabatech.com/schema/dubbo
- http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
我们都知道Spring在启动时是要检验XML文件的。或者为什么在Eclipse里xml没有错误提示?
比如这样的一个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"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
- </beans>
我们也可以在后面加上版本号:
- 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:
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xmlns:context="http://www.springframework.org/schema/context"
通常情况下,namespace对应的URI是一个存放XSD的地址,尽管规范没有这么要求。如果没有提供schemaLocation,那么Spring的XML解析器会从namespace的URI里加载XSD文件。我们可以把配置文件改成这个样子,也是可以正常工作的:
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans/spring-beans.xsd"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
schemaLocation提供了一个xml namespace到对应的XSD文件的一个映射,所以我们可以看到,在xsi:schemaLocation后面配置的字符串都是成对的,前面的是namespace的URI,后面是xsd文件的URI。比如:
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/security
- 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
- http\://www.springframework.org/schema/context=org.springframework.context.config.ContextNamespaceHandler
- http\://www.springframework.org/schema/jee=org.springframework.ejb.config.JeeNamespaceHandler
- http\://www.springframework.org/schema/lang=org.springframework.scripting.config.LangNamespaceHandler
- http\://www.springframework.org/schema/task=org.springframework.scheduling.config.TaskNamespaceHandler
- http\://www.springframework.org/schema/cache=org.springframework.cache.config.CacheNamespaceHandler
spring.schemas
- http\://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd
- http\://www.springframework.org/schema/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd
- http\://www.springframework.org/schema/context/spring-context-3.1.xsd=org/springframework/context/config/spring-context-3.1.xsd
- http\://www.springframework.org/schema/context/spring-context-3.2.xsd=org/springframework/context/config/spring-context-3.2.xsd
- http\://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.2.xsd
- ...
再打开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文件:
- http\://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.2.xsd
同样,我们打开dubbo的jar包,可以在它的spring.schemas文件里看到有这样的配置:
- 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重新验证即可。
【Dubbo&&Zookeeper】3、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'问题解决方法
Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd'问题解决方法 关于dubbo服务的 ...
- cvc-elt.1: Cannot find the declaration of element 'beans'Failed to read schema document 'http://www.springframework.org/schema/beans/spring- beans-3.0.xsd'
Multiple annotations found at this line: - cvc-elt.1: Cannot find the declaration of element 'beans' ...
- webServices接口开发过程中项目启动遇到的错误org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 422; schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-bean
org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 422; schema_reference.4: Failed to read ...
- Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans.xsd'
明明项目没错误,但application.xml就报了错误,这是什么问题呢? 问题在于我们找不到org/springframework/beans/spring-beans这个包,也就是我们的spri ...
- linux上启动tomcat报错:Failed to read schema document 'http://www.springframework.org/schema/data/mongo/spring-mongo-2.0.xsd
本文原文连接: http://blog.csdn.net/bluishglc/article/details/7596118 ,转载请注明出处! spring在加载xsd文件时总是先试图在本地查找xs ...
- Failed to connect to 127.0.0.1 port 1080: Connection refused package 问题解决方法
错误: fatal: unable to access 'https://github.com/******': Failed to connect to 127.0.0.1 port 1080: C ...
- (转)解决dubbox-demo-provider.xml报错的问题:提示Failed to read schema document
背景:在eclipse项目中,经常会遇到xml文件提示找不到.xsd文件的情况.很有必要弄清xsd文件的加载过程! 1 解决过程 dubbo-demo-provider导入eclipse后dubbox ...
- eclipse中不能找到dubbo.xsd解决方法
使用dubbo时遇到问题: org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'htt ...
- Spring如何加载XSD文件(org.xml.sax.SAXParseException: Failed to read schema document错误的解决方法)
今天配置Spring的xml出现了错误 Multiple annotations found at this line: - schema_reference.4: Failed to read sc ...
随机推荐
- 【慕课网实战】Spark Streaming实时流处理项目实战笔记十七之铭文升级版
铭文一级: 功能1:今天到现在为止 实战课程 的访问量 yyyyMMdd courseid 使用数据库来进行存储我们的统计结果 Spark Streaming把统计结果写入到数据库里面 可视化前端根据 ...
- ASP.NET对大文件上传的解决方案
在ASP.NET 开发的过程中,最大的问题就在于上传大文件时让开发者尤为的头疼,而且,上传时无法方便的做到多线程的操控和上传进度的显示.笔者在此给大家推荐一款简单易用的上传组件,从而快速便捷得解决了 ...
- 利用python同步windows和linux文件
写python脚本的初衷,每次在windows编辑完文件后,想同步到linux上去,只能够登录服务器,然后再利用网络copy,重复性很大,就想着能不能写一个小脚本帮我同步 逻辑:比对本地和服务器文件的 ...
- Html5与Css3知识点拾遗(五)
css3更新的颜色 RGBA:红.绿.蓝.不透明度 rgba(89,0,127,0.4); HSL和HSLA:色相.饱和度.亮度.不透明度 hsl(282,100%,25%); hsl(282,100 ...
- TabLoaout简单框架
import android.os.Bundle; import android.support.annotation.Nullable; import android.support.design. ...
- 数组-Array
1.数组的概念 /* 数组的格式 数组: 同一种数据类型的若干个值的容器 元素:数组中的值称为元素 索引:元素的标号,从0开始 长度:数组中元素的个数 */ public class ArrayDem ...
- 利用ArcGIS-Server瓦片制作离线地图包(*.tpk)_详细流程
1.写在前面 本人是综合了好几个资料才最终制作成功,在这个过程中发现网上好多博客写的步骤不是很详细,因此就把自己的详细制作步骤全部分享出来,可以供需要的小伙伴参考. (1)本文档不讨论tpk文件的详细 ...
- 腾讯云播放器更新——TCplayer
概述 最近腾讯云播放器进行了更新,增加了TCplayer,支持点播播放.由于工作需要,了解了一下TCplayer,把心得记录下来,供以后开发时参考,相信对其他人也有用. 参考文档: TCPlayer开 ...
- LabVIEW(十):数组和簇
一.数组 1.创建数组 (1).前面板右键>“数组.矩阵与簇”>数组. (2).前面板右键>(选择要添加的数组数据类型,比如创建数值数组)数值>将“数值输入控件”拖入数组中. ...
- MySQL:基础架构和工作流程
[参考文章]:01|基础架构:一条查询语句的执行流程 1. 基本架构 大体来说,MySQL可以分为Server层和存储引擎两部分. Server层包括链接器,分析器,优化器,执行器等,涵盖大多数核心服 ...