给ibatis加cache时, 碰到一直报"The content of element type "cacheModel" must match "(flushInterval?,flushOnExecute*,property*)+". " 这个异常. 查了头天, 自己的格式完全符合, 最后把这些文件找出来单独验证. 我的XML:
card.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "\bin\validateXML\sql-map.dtd">
<sqlMap namespace="card">
<cacheModel id="product-cache" type="LRU">
<flushInterval hours="24"/>
<flushOnExecute statement="insertProduct"/>
<flushOnExecute statement="updateProduct"/>
<flushOnExecute statement="deleteProduct"/>
<property name="size" value="1000" />
</cacheModel>
</sqlMap>
sql-map.dtd的cacheModel部分:
<!ELEMENT cacheModel (flushInterval?, flushOnExecute*, property*)+>
<!ATTLIST cacheModel
id CDATA #REQUIRED
type CDATA #REQUIRED
readOnly (true | false) #IMPLIED
serialize (true | false) #IMPLIED
>
使用验证程序:
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
public class ValidateXMLDTD {
public static void main(String[] args) {
testXML();
}
public static void testXML() {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
DocumentBuilder db = dbf.newDocumentBuilder();
db.parse(ValidateXMLDTD.class.getResourceAsStream("card.xml"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
其中sql-map.dtd给的example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "\bin\validateXML\sql-map.dtd">
<sqlMap namespace="card">
<cacheModel id="product-cache" type="LRU">
<flushInterval hours="24"/>
<flushOnExecute statement="insertProduct"/>
<flushOnExecute statement="updateProduct"/>
<flushOnExecute statement="deleteProduct"/>
<property name="size" value="1000" />
</cacheModel>
</sqlMap>
在内容上无论怎么比较都一样, 最后一句一句的替换, 看到底错在哪句上面, 还是会报错, 最终只感觉内容完全一样, 只是不美观, 格式化一下, 再测试, 发现没有错, 原来是自的XML的flushOnExecute前多了一个空格, dtd给出"(flushInterval?, flushOnExecute*, property*)+" 这种约束时元素中间不能出现空格, 但可以使用制表符, 当dtd给出"(#PCDATA | include | dynamic | iterate)"约束时, 元素中间既可以是空格, 也可以是制表符.
删除空格, 使用tab键, 大功告成.....
分享到:
相关推荐
很好的spring+ibatis事务的配置文档.
ibatis配置ibatis配置ibatis配置ibatis配置ibatis配置 以及相关资料
ibatis 实例 配置 源码 依赖包 ibatis-2.3.4.726.jar commons-logging-api.jar commons-logging-1.1.jar commons-dbcp-1.2.2.jar commons-pool.jar
Struts+Spring+Ibatis环境配置(一) - zwjxf的专栏 - 博
ibatis用xml配置文件配置的使用,基本包括了ibatis遇到的所有问题
Struts 1.2.9 + Spring 2.5.6 + iBATIS 2.3.4 + MySQL 3.1 + Tomcat 5.5.26 > 开发环境: * MyEclipse、JDK1.5、J2EE1.4 > 使用技术: * Struts1、Spring、iBATIS > 运行环境: * Window + Tomcat 5.5.26 + ...
Ibatis基本配置---[环境搭建
此文本主要是关于ibatis总配置和映射配置和一些需要主要的细节。
SPRING与IBATIS整合采用保留IBATIS事务,可自己控制回滚!
java笔试题
Struts2+Spring+Ibatis环境配置.doc 详细讲解如何配置Struts2+Spring+Ibatis开发环境
ibatis的配置文件和映射文件,以及ibatis的应用
ibatis 配置文件详解
用spring改造的jpetstore4.0,适用于jdk7+,tomcat6+。mysql数据库
iBATIS是以SQL为中心的持久化层框架。能支持懒加载、关联查询、继承等特性
spring+ibatis实例,包括用到的各种包,标准的开发目录组织,你值得拥有
SqlMap的配置是iBatis中应用的核心。这部分任务占据了iBatis开发的70的工作量。Sql Map配置文件是iBatis配置的核心,从数据库连接到执行SQL时使用的sqlMap文件都是通过此文件中的配置提供给框架的,它通常命名为...
博客地址:http://www.cnblogs.com/jys509/p/4543289.html
ibatis 缓存配置策略,学习篇 • iBatis对查询结果集进行本地缓存。 • Cache的key由haskcode、checksum、查询参数、sqlmap Id、sql语句、调用方法名等构成。由此可以看出,不同的参数会有不同的Key。注意,他不是以...
spring ibatis 配置spring ibatis 配置spring ibatis 配置spring ibatis 配置