ibatis错误汇总
1) 错误:The prefix "context" for element "context:property-placeholder" is not bound.
解决:在文件头中引入:xmlns:context="http://www.springframework.org/schema/context" 就可以。
正解样例:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire="byName">
<context:property-placeholder location="classpath:META-INF/app.properties" />
2) 错误:Cannot convert value of type [org.springframework.jdbc.datasource.DriverManagerDataSource] to required type [com.ibatis.sqlmap.client.SqlMapClient] for property 'sqlMapClient': no matching editors or conversion strategy found
原因:property sqlMapClient 引错了id;一開始ref的不是baikeZhangzishiSqlMapClientReadonly,而是baikeZhangzishiDataSourceReadonly
正解:
<bean id="baikeZhangzishiReadTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate" destroy-method="close">
<property name="sqlMapClient"><ref bean="baikeZhangzishiSqlMapClientReadonly" /></property>
</bean>
<bean id="baikeZhangzishiDataSourceReadonly" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/mysqlAppsDataSourceReadonly</value>
</property>
</bean>
<bean id="baikeZhangzishiSqlMapClientReadonly" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:/ibatis/baikeZhangzishi-sqlmap.xml</value>
</property>
<property name="dataSource" ref="baikeZhangzishiDataSourceReadonly"></property>
</bean>
3)有例如以下两个错误:
错误1:com.ibatis.sqlmap.client.SqlMapException: There is no statement named MS-APPBAIKEZHANGZISHI-ADDINFO in this SqlMap.
错误2:java.lang.NullPointerException
at com.hudong.apps.baikesurvey.dao.impl.BaikeZhangzishiWriteDAOImpl.addBaikeZhangzishi(BaikeZhangzishiWriteDAOImpl.java:29)
at com.hudong.apps.baikesurvey.dao.test.BaikeZhangzishiDAOTest.testAdd(BaikeZhangzishiDAOTest.java:81)
at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:163)
分析:从表面上看,这两个错误系属一个错误,都是sqlMap找不到,可能是相关的xml配置找不到,也可能是id错误,也可能是set注入错误;
我犯得错误是set注入错误,所以在做一些底层东西copy的时候一定要注意这些细节,看看id有没有负责后忘了更改,从而导致set注入相关的spring id,还应该注意的是假设原project使用了高度封装,比方创建一个basedao 存放一些set注入等信息的时候,这时候copy的东西一定要去这个base类中加入对应的模块,比方set注入模块
4)1ibatis错误
com.ibatis.sqlmap.client.SqlMapException: There is no statement named MS-QUERY-TOP-PAGE in this SqlMap.
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:231)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:558)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
错误分析:ibatis+spring+jndi+resin使用的使用一定要注意一些配置上面的细节;我这里所犯的错误是由于ibatis配置引用底层sqlxml的时候没有放到sqlMapConfig中;注意jndi的配置不能直接引用ibatis的底层sql文件,必须引用有sqlMapConfig配置的xml文件;
错误例如以下:
jndi 直接引用sql的xml;
<!-- dataSource readonly -->
......
<bean id="topSqlMapClientReadonly" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:/ibatis/com/hudong/apps/baikesurvey/sqlmap/top1000-readonly-sqlmap-mapping.xml</value>
</property>
<property name="dataSource" ref="topDataSourceReadonly"></property>
</bean>
......
正确使用:
<!-- dataSource readonly -->
<bean id="topDataSourceReadonly" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/mysqlDataSourceReadonly</value>
</property>
</bean>
<bean id="topSqlMapClientReadonly" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:/ibatis/baikeSurvey-sqlmap.xml</value>
</property>
<property name="dataSource" ref="topDataSourceReadonly"></property>
</bean>
<bean id="topReadTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate" destroy-method="close">
<property name="sqlMapClient"><ref bean="topSqlMapClientReadonly"/></property>
</bean>
注意ibatis的sqlmap配置,一定要放入sqlMapConfig中;这里另一点要注意的,那就是useStatementNamespaces命名空间的配置,这里假设设置成了false,那么底层sql配置文件就能够不配置命名空间;假设设置成了true,那么必须配置命名空间,否则也会出现这个错误
<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings cacheModelsEnabled="true" enhancementEnabled="false" lazyLoadingEnabled="false" maxRequests="3000" maxSessions="3000" maxTransactions="3000" useStatementNamespaces="false"/>
<sqlMap resource="ibatis/com/hudong/apps/baikesurvey/sqlmap/top1000-readonly-sqlmap-mapping.xml"/>
</sqlMapConfig>
命名空间的配置,注意多个sql xml命名空间不能反复;例如以下:
<sqlMap namespace="topReadSqlMap">
未完待续
ibatis错误汇总的更多相关文章
- Entity Framework学习笔记——错误汇总
之前的小项目做完了,到了总结经验和更新学习笔记的时间了.开始正题之前先啰嗦一下,对之前的学习目标进行一个调整:“根据代码生成表”与“生成数据库脚本和变更脚本”合并为“Code First模式日常使用篇 ...
- 李洪强iOS开发之OC常见错误汇总
// // main.m // 16 - 常见错误汇总 // // Created by vic fan on 16/7/13. // Copyright © 2016年 李洪强. All r ...
- Python常见的错误汇总
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 错误: [错误分析]第二个参数必须为类,否则会报TypeError,所以正确的应 ...
- PHP常见错误汇总
日常开发和调试的时候,经常会遇到一些错误,光怪陆离的不知所以,所以,特此将错误汇总一下,借鉴!!! 1. 原因分析: 一般可能是该文件出现了问题,检查一下代码和格式,是否出现开始的地方出现了空格,或 ...
- Quartus II 中 Verilog 常见警告/错误汇总
Verilog 常见错误汇总 1.Found clock-sensitive change during active clock edge at time <time> on regis ...
- android studio 错误汇总以及解决办法
android studio 错误汇总以及解决办法 参考 https://www.jianshu.com/p/7c7de6562231 问题1. Error:Execution failed for ...
- 编程中易犯错误汇总:一个综合案例.md
# 11编程中易犯错误汇总:一个综合案例 在上一篇文章中,我们学习了如何区分好的代码与坏的代码,如何写好代码.所谓光说不练假把式,在这篇文章中,我们就做一件事——一起来写代码.首先,我会先列出问题,然 ...
- react 报红错误汇总
react 报红错误汇总 一.Uncaught TypeError: Cannot read property 'value' of undefined 未知类型错:无法读取未定义的属性“value ...
- Jmeter工具做性能测试 常见的错误汇总
在Win机器上用Jmeter做性能测试,汇总下我自身遇到的错误和解决方案 java.net.BindException: Address already in use: JVM_Bind 原因分析:压 ...
随机推荐
- [每日一题] OCP1z0-047 :2013-08-17 EXTERNAL TABLE――加载数据 ............................56
正确答案:C 一.对答案解释: A. TYPE:有两个选可供选择: 1. ORACLE_LOADER:传统方式,与SQLLDR一样,参数从多,应用较多. 2. ...
- HDU 1813 Escape from Tetris (IDA*)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1813 题意:给你一个n*n的迷宫,其中0代表有一个人在这个位置,1代表墙,现在要求一个路线,使所有的人通 ...
- asp.net 追加文本(追加写入记事本)
代码: string path = Server.MapPath("/Log/Log.txt"); if (File.Exists(path)) { using (StreamWr ...
- ASP.NET中的Request和Respone对象的使用
前台<body>中的表单代码: ASP.NET对象有如下几个: 本文从“asp.net中通过from表单submit提交到后台的实例”来谈谈Request和Response ...
- C#图像处理(1):在图片上加文字和改变文字的方向
C#在图片上加文字,代码如下: /// <summary> /// 图片上方加文字,文字将会被180度反转 /// </summary> /// <param name= ...
- jquery动态添加DOM节点
1.append()方法:向每个匹配的元素内部添加元素 appendTo()方法:将所有匹配的元素追加的指定的元素中 <html> <head> <meta http-e ...
- Struts2学习笔记 国际化(Internationalization)
概述 国际化(Internationalization),通途的讲,就是让软件实现对多种语言的支持.可以通过简单的设置就可以从一种语言切换到另一种语言.用的最多的地方就是在应用程序的界面表示上.我们经 ...
- Emacs颜色设置
1.下载color-theme主题包 下载链接:http://download.savannah.gnu.org/releases/color-theme/ color-theme-6.6.0.zip ...
- c中关于#与##的简易使用
#运算符用于在预编译时,将宏参数转换为字符串 eg. #include <stdio.h>#define CONVERT(f)(#f) void helloworld(){ printf( ...
- mysql升级后报Table 'mysql.servers' doesn't exist
解决Table 'mysql.servers' doesn't exist 今天遇到一事,就是我在升级mysql数据库后进入数据建立一远程用户,结果报错了. mysql> flush privi ...