首页 > 系统服务 > 详细

cvc-elt.1: Cannot find the declaration of element 'ehcache'.

时间:2015-06-02 17:53:46      阅读:3377      评论:0      收藏:0      [点我收藏+]

在Spring项目中配置缓存时出现异常:


org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from file [D:\workspaces\eclipse_svn\NewsPortalProject\WebContent\WEB-INF\classes\config\ehcache.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element ‘ehcache‘.


是在配置文件中省略命名空间语句导致的~


原配置文件

<ehcache>
    <diskStore path="java.io.tmpdir"/> 
    <defaultCache 
           maxElementsInMemory="1000"
           eternal="false"
           timeToIdleSeconds="10"
           timeToLiveSeconds="10"
           overflowToDisk="false"/>
    <cache name="newslist"
    	   eternal="false"
    	   timeToIdleSeconds="360" 
           timeToLiveSeconds="3600"
           maxElementsInMemory="100"
           overflowToDisk="false"
           diskPersistent="false"
           memoryStoreEvictionPolicy="LRU" />
</ehcache>

添加命名空间之后的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
 updateCheck="false">
    <diskStore path="java.io.tmpdir"/> 
    <defaultCache 
           maxElementsInMemory="1000"
           eternal="false"
           timeToIdleSeconds="10"
           timeToLiveSeconds="10"
           overflowToDisk="false"/>
    <cache name="newslist"
    	   eternal="false"
    	   timeToIdleSeconds="360" 
           timeToLiveSeconds="3600"
           maxElementsInMemory="100"
           overflowToDisk="false"
           diskPersistent="false"
           memoryStoreEvictionPolicy="LRU" />
</ehcache>


解释:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"中xsi的意思是 :
本xml文件中要用到某些来自xsi代表的“http://www.w3.org/2001/XMLSchema-instance”这个命名空间的元素 
比如用来引入无命名空间schema文件的noNamespaceSchemaLocation="XXX";
以及引入自带命名空间的schema文件的schemaLocation="XXX"这些元素。
这些元素是包含在xsi命名空间中的,所有的xml文件只要引用这些元素 就要引入xsi这个命名空间。  
xsi这三个字母不是硬性规定,只是大家都这么用,方便阅读而已。

cvc-elt.1: Cannot find the declaration of element 'ehcache'.

原文:http://blog.csdn.net/jeofey/article/details/46332075

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!