-
Dec 15th, 2005, 09:05 PM
#1
Ibatis problem
when I use spring_ibatis encounter problem,error message as follows:
Exception in thread main
java.lang.IllegalArgumentException: No SqlMapClient specified
at org.springframework.util.Assert.notNull(Assert.jav a:90)
at org.springframework.orm.ibatis.SqlMapClientTemplat e.execute(SqlMapClientTemplate.java:155)
at org.springframework.orm.ibatis.SqlMapClientTemplat e.executeWithListResult(SqlMapClientTemplate.java: 204)
at org.springframework.orm.ibatis.SqlMapClientTemplat e.queryForList(SqlMapClientTemplate.java:243)
at com.ztht.rms.sysman.dao.ibatis.SqlMapDepartmentDao .selectDepartmentListByAll(SqlMapDepartmentDao.jav a:22)
at com.ztht.rms.sysman.test.DepartmentDaoTest.main(De partmentDaoTest.java:27)
Process exited with exit code 1.
1, sqlmapping souce
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="Department">
<resultMap id="result" class="com.ztht.rms.sysman.domain.DepartmentVO">
<result property="deptId" column="dept_Id" columnIndex="1"/>
<result property="superiorId" column="superior_Id" columnIndex="2"/>
<result property="empId" column="emp_Id" columnIndex="3"/>
<result property="name" column="name" columnIndex="4"/>
<result property="description" column="description" columnIndex="5"/>
</resultMap>
<select id="selectDepartmentListByAll" resultMap="result">
select
dept_Id,
superior_Id,
emp_Id,
name,
description
from Department
</select>
<select id="selectDepartmentByDeptId" resultMap="result">
select
dept_Id,
superior_Id,
emp_Id,
name,
description
from Department
where dept_Id = #dept_Id#
</select>
2.data_acess source
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- SqlMap setup for iBATIS Database Layer -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
<property name="configLocation" value="WEB-INF/sql-map-config.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- ========================= DAO DEFINITIONS: IBATIS IMPLEMENTATIONS ========================= -->
<bean id="departmentDao" class="com.ztht.rms.sysman.dao.ibatis.SqlMapDepart mentDao">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
</beans>
3.sqlmapping config
<sqlMapConfig>
<sqlMap resource="com/ztht/rms/sysman/dao/ibatis/maps/Department.xml"/>
</sqlMapConfig>
4.java source
public class SqlMapDepartmentDao extends SqlMapClientDaoSupport implements DepartmentDao
{
public List selectDepartmentListByAll() throws DataAccessException
{
return (List) getSqlMapClientTemplate().queryForList("selectDepa rtmentListByAll", null);
}
}
how to solve this problem?
how to check the database is connected?
-
Feb 16th, 2006, 09:03 AM
#2
Maybe try changing the property for the sqlMapClient in your DAO to be set this way:
<property name="sqlMapClient">
<ref local="sqlMapClient"/>
</property>
Also, to test your database bean you could always write a small servlet or something that would access the WebApplicationContext and retrieve the bean. That way you could see if the bean itself was being created OK.
HTH.
Daniel
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules