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,还应该注意的是如果原工程使用了高度封装,比如创建一个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>