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 原因分析:压 ...
随机推荐
- 打印log 保存log
using UnityEngine; using System.Collections; using System.IO; using System; using System.Text; names ...
- JS中for循环里面的闭包问题的原因及解决办法
我们先看一个正常的for循环,普通函数里面有一个for循环,for循环结束后最终返回结果数组 function box(){ var arr = []; for(var i=0;i<5;i++) ...
- Entity Framework中datetime2 to datetime转换错误
datetime2 to datetime 报错. 因为EF中,DATETIME类型默认是datetime2,数据库默认是datetime. 解决方案: 1.改数据库字段类型为datetime2 2. ...
- (转)Ubuntu中让终端对于历史输出的内容保持足够长
原地址:http://www.crifan.com/ubuntu_terminal_make_retain_long_enough_history_output_content/ Ubuntu下用终端 ...
- UnSupported Encoding错误
学习struts2的时候碰到tomcat报错:org.apache.jasper.JasperException: Unsupported encoding: UTF-8,原因是jsp文件中的pag ...
- php代码查询apache模块
<?php print_r(apache_get_modules()); ?> 注:此函数仅适用于CGI模式.
- SSH 5W学习
what SSH的英文全称为Secure Shell,是IETF(Internet Engineering Task Force)的Network Working Group所制定的一族协议,其目的是 ...
- 通过meteor实现的一个照片墙
always love tech 初次使用meteor所遇到的一个问题: insert failed: Method '/pictures/insert' not found 提示没有这个方法,然后可 ...
- Spring连接MySQL、Oracle和SQL Server的数据库运动连接属性
在配置文件applicationContext.xml设置如下:<?xml version="1.0" encoding="UTF-8"?>< ...
- 远程访问TeamTalk的Mysql数据库被拒解决方法
1.A Database Error Occurred 问题如图: 蓝狐给的解答是: 这是访问mysql出错了.解决办法参考:http://www.bkjia.com/jingyan/512248.h ...