ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Meindert" <meind...@pastelebusiness.com>
Subject converting iBATIS framework DAOs to the Spring Framework
Date Thu, 12 Apr 2007 10:03:43 GMT

Hi all.

I've documented the process of converting jpetshop5, and would like to know
if it is right?

Also I don't know what to do with the com.ibatis.dao.client.DaoException
thrown in SequenceSqlMapDao?

I'm going to add the transaction on OrderService now.


Steps to convert jpetshop5 to ibatis-spring 


The DAO iBATIS has been depreciated and it is recommended to replace this
with the spring framework <http://www.springframework.org/> . This document
describes the steps taken to convert from ibatis dao to spring dao. I work
on the project in netbeans so some terminology used might be incorrect for
other IDE's


Prerequisite is to have a project similar to jpetstore5, and have it
connected to a 'normal' database

(There is support for hssqldb in the DaoConfig class what we are going to
throw away.)


Lib jar files;

Remove the old ibatis jar files from the class path and create the reference
to the new ibatis and spring jars

*	Remove ibatis-common-2.jar
*	Remove ibatis-dao-2.jar
*	Remove ibatis-sqlmap-2.jar
*	Add ibatis-
*	Add spring.jar
*	Add commons-dbcp-1.2.1.jar
*	Add commons-pool-1.2.jar
*	Add commons-collections.jar



Change the BaseSqlMapDao to;

package com.ibatis.jpetstore.persistence.sqlmapdao;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

public class BaseSqlMapDao extends SqlMapClientTemplate {

    protected static final int PAGE_SIZE = 4;


All the other SqlMapDao files;

Remove the public AccountSqlMapDao(DaoManager daoManager)  methode

Remove import com.ibatis.dao.client.DaoManager;


The DAO will be injected by spring, thus the constructor can be deleted

Example for AccountService, remove the public AccountService()methode

(also remove import com.ibatis.dao.client.DaoManager;)

There is a transaction in OrderService.java, this transaction must be
handled by Spring, remove it here for now. Also remove it out of the

public OrderService(ItemDao itemDao, OrderDao orderDao, SequenceDao
sequenceDao) {

    this.itemDao = itemDao;

    this.orderDao = orderDao;

    this.sequenceDao = sequenceDao;



The Link between spring and ibatis

Add the SpringInit.java class to a new package com.listeners

This class will be instantiated on load of the website and will pass the
reference to the spring managed objects



The presentation layer must connect with the spring managed service layer

So replace;

public AccountBean() {

    this(new AccountService(), new CatalogService());



public AccountBean() {




And add import com.listeners.SpringInit;

Repeat for the other classes



First setup the listeners to have SpringInit initiated on loading of the

Add to web.xml (after <description> tag)














As you can see it is looking for /WEB-INF/spring.xml create this file.
Attached is the one I created for jpetstore5



Throw away DaoConfig.java and dao.xml out of
com.ibatis.jpetstore.persistence, and the reference to it in the Service


View raw message