Hi,

I've done something close to this (my actions did not depend on Spring 
directly).
I've been using Struts/iBATIS Dao/SqlMap for a while. I've changed to Spring 
Dao. To use DI in an "semi-automatic way", I've used the @SpringBean annotation 
from Stripes (since Spring didn't support annotations back then).
To do injection without being aware of Spring (it tied my actions to Stripes, 
but you can easily writte your own annotation to do the same thing based on 
Stripes code).

This is a part of a custom class I used for DI.

import net.sourceforge.stripes.integration.spring.SpringHelper;

/**

* Inject Spring dependence into object.

* If object was created by cglib, this method may not be able to set beans 
correctly.

* @param object Object.

*/

public static void injectBeans(Object object) {

SpringHelper.injectBeans(object, applicationContext);

}



A Struts action
public class MyAction extends Action {
    @SpringBean MyService myService;
    public MyAction() {
        SpringInjector.injectBeans(this);
    }
}


Stripes is available here http://www.stripesframework.org/display/stripes/Home

This will not relieve you of DI, but it's a possible way to get around 
dependency on spring for your actions.

Christian



________________________________
From: Kenan Azam [mailto:[EMAIL PROTECTED]
Sent: Friday, June 27, 2008 5:52 PM
To: [email protected]
Subject: Using Struts with Spring DAO's in IBATIS

Hi there,
We have an application where we are using Struts as our web framework and 
IBATIS in the data layer. We upgraded to the new version of ibatis which 
required to upgrade the DAO's to Spring DAO's.

To use the Spring DAO's we started to use spring with struts. The only purpose 
of Spring was to inject the dao's into the service classes and into my Struts 
Action. However , this approach ties my Struts framework with Spring. Because, 
the beans.xml file tries to see Struts Action classes as Beans to do its 
injection.


<action-mappings>

        <action
                path="/employeeSetUp"
                name="employeeForm"

                type="org.springframework.web.struts.DelegatingActionProxy"



This approach however, ties Ibatis to Spring and forces us to use Spring in our 
web layer as well.

Can I use Spring DAO's without doing dependency injection?
Has anyone used Ibatis Spring DAO's in Struts without making Struts aware of 
the existence of Spring. Any pointers are appreciated.

Thanks.

Reply via email to