Hi Christian,

 

Thanks for your extensive answer, unfortunately I don't seem to be clever
enough to understand it..

I've never worked with Listeners before and don't understand most of what is
going on :-(

 

Anyway,

I added your sample code into a com.listeners package, and added a entry
into web.xml to call it;

<listener>

   <listener-class>com.listeners.SpringInit</listener-class>

 </listener>

 

I put a debug line into the context Initialization to check if it finds the
Spring bean, it doesn't..

WebApplicationContextUtils.getWebApplicationContext(event.getServletContext(
)); 

returns null

 

My service class seems to get created by the spring framework, (it does stop
at a breakpoint I put in).

So my entry in Spring.xml is probably correct (how do you debug all these
configuration file?!)

<bean id="theService" class="com.service.TheService">

  <constructor-arg index="0" ref="theDao"/>

</bean>

  _____  

From: Poitras Christian [mailto:[EMAIL PROTECTED] 
Sent: 10 April 2007 07:10 PM
To: user-java@ibatis.apache.org
Subject: RE: iBATIS, Spring, and transactions...

 

First, you can still use BeanAction with Spring DAO.

 

The most simple solution to set your static variable is to get it from
Spring.

First get the SpringContext and do the following.

private static final TheService instance =
springContext.getBean("theService");

 

The way you can get SpringContext is relaitve on how you initialize it. This
is a code sample of how you can access it if you use
org.springframework.web.context.ContextLoaderListener.

/**
 * Listen for Spring initialization.
 * 
 * @author poitrac
 */
public class SpringInit implements ServletContextListener {
    
    /**
     * Spring's WebApplicationContext.
     */
    private static WebApplicationContext springContext;
    
    public SpringInit() {
        super();
    }
    
    /* (non-Javadoc)
     * @see
javax.servlet.ServletContextListener#contextInitialized(javax.servlet.Servle
tContextEvent)
     */
    public void contextInitialized(ServletContextEvent event) {
        springContext =
WebApplicationContextUtils.getWebApplicationContext(event.getServletContext(
));
    }
    
    /* (non-Javadoc)
     * @see
javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletC
ontextEvent)
     */
    public void contextDestroyed(ServletContextEvent event) {
    }
    
    /**
     * Returns Spring's WebApplicationContext.
     * @return Spring's WebApplicationContext.
     */
    public static ApplicationContext getApplicationContext() {
        return springContext;
    }
}

 

Christian

 

  _____  

From: Meindert [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, 10 April 2007 12:30
To: user-java@ibatis.apache.org
Subject: RE: iBATIS, Spring, and transactions...

I'm busy converting and went to the site
http://www.learntechnology.net/content/ibatis/spring_ibatis.jsp

What is quite a clear explanation :-)

 

I'm converting a project that is based on the jpetstore, what is using
org.apache.struts.beanaction.BeanAction in my struts-config.xml

The above mentioned site has got a different approach.

My question is;

a) can I still use org.apache.struts.beanaction.BeanAction? I only want to
change the DAO to Spring DAO because IBATIS DAO is depreciated

and if so

b) The BeanAction class is using

private static final TheService theService = TheService.getInstance();

to connect with the service object, what created itself static;

private static final TheService instance = new TheService();

 

How do I get a instance from the spring created service object?

My service object get's created by spring using the following config in
spring.xml;

<bean id=" theService " class="com.service.TheService ">

        <constructor-arg index="0" ref="theDao"/>

    </bean>

And code;

public TheService (TheDao theDao){

      this.theDao = theDao;

  }

 

Kind Regards

 Meindert

 

 

 

-----Original Message-----
From: Poitras Christian [mailto:[EMAIL PROTECTED] 
Sent: 10 April 2007 04:25 PM
To: user-java@ibatis.apache.org; [EMAIL PROTECTED]
Subject: RE: iBATIS, Spring, and transactions...

 

That would be a great idea!

It's always welcome to see some code to show each steps. My app is

already to big to use it direclty as an example... 

 

Christian

 

I'll check if I can provide you with my smaller app (contains only 2

actions, but it does not have any transaction).

I'll just add the insert/updates I used at first to fill database.

 

-----Original Message-----

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf

Of Larry Meadors

Sent: Tuesday, 10 April 2007 10:16

To: user-java@ibatis.apache.org

Subject: Re: iBATIS, Spring, and transactions...

 

That would be AWESOME, if you want, I can help with proofing, etc.

 

Maybe someone else would be willing to provide a *simple* iBATIS DAO

sample application that we could convert and then document the process.

 

Larry

 

 

On 4/10/07, Poitras Christian <[EMAIL PROTECTED]> wrote:

> I have to say that it would be really nice to have an "how to" for 

> passing from iBATIS DAO to Spring DAO...

> I made a french document about that question. I could transalte it to 

> english in the next weeks and put it on the wiki...

Reply via email to