xsi:noNamespaceSchemaLocation使用心得

在使用ehcache的时候碰到一个问题:
is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ehc
ache'

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


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

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

比如:
如果,ehcache.xsd 和 ehcache.xml文件同目录下面
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="false" dynamicConfig="false">

这样配置是错误的,加载不了的;
那么要如何配置
xsi:noNamespaceSchemaLocation=""

看了一下源代码
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(InputSource inputSource, Resource resource)

Resource:我首先想到的就是:classpath:META-INF/spring/ehcache.xsd
没有仔细看,直接改上去:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="classpath:META-INF/spring/ehcache.xsd"
updateCheck="false" dynamicConfig="false">


OK 跑通过了,就是这样对的,没错,好了,以后类是的问题都可以这样处理
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值