您的位置:首页 > 其它

xsi:noNamespaceSchemaLocation使用心得

2017-10-10 11:03 239 查看
在使用ehcache的时候碰到一个问题: 

Java代码  


is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ehc  

ache'  

Java代码  


Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ehcache'  

分析下来就是 ehcache.xml文件加载出问题了,根据错误可以看出是"ehcache"节点无法解析,那么首先就可以想到是描述文件出错ehcache.xsd; 
为什么加载不到呢在本地直接

Java代码  


curl -X GET http://ehcache.org/ehcache.xsd   

发现确实是链接不到服务器,发现是内网机器无法访问网络; 
定位到问题首先想到的就是,那把ehcache.xsd下载到本地直接读,思路是正确的,只是文件路径的设置需要注意一下 

比如: 
如果,ehcache.xsd 和 ehcache.xml文件同目录下面 

Java代码  


<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  

    xsi:noNamespaceSchemaLocation="ehcache.xsd"  

    updateCheck="false" dynamicConfig="false">  

这样配置是错误的,加载不了的; 
那么要如何配置

Java代码  


xsi:noNamespaceSchemaLocation=""  

? 
看了一下源代码

Java代码  


org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(InputSource inputSource, Resource resource)  

Resource:我首先想到的就是:classpath:META-INF/spring/ehcache.xsd 
没有仔细看,直接改上去: 

Java代码  


<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  

    xsi:noNamespaceSchemaLocation="classpath:META-INF/spring/ehcache.xsd"  

    updateCheck="false" dynamicConfig="false">  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: