• 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">


    未完待续

  • 相关阅读:
    笔记 : windows系统下 命令行 php --version 的版本与phpinfo()版本不一致问题
    笔记 : WampServe加装PHP版本(7.2.3)为例
    Browsersync结合gulp和nodemon实现express全栈自动刷新
    PHP与JSP简单比较
    BDD 与DSL 入门
    1.display:flex布局笔记
    Css预处理器---Less(三)
    python_30期_第2讲【字符串&运算符】
    python_30期_第5讲【while循环+for循环】
    class_05py作业
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4030950.html
Copyright © 2020-2023  润新知