Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

newbie question...struts2, spring and jdbc

Cecilia Castillo

2007-01-31

Replies:

I am new to Struts, Struts2, and Spring. (And maybe know too much about jdbc.)

I have written my application with Struts2 and am only using Spring
to manage my database connections. I have defined my oracle database
as a JNDI resource in my Tomcat server.xml file.

I have defined a dataSource bean in my applicationContext.xml for my
database JNDI resource.

I have written some DAO classes which are spring beans defined in my
applicationContext.xml. These all have a dataSource property
pointing to my database. These DAO classes have methods which
execute various db stored procedures or select statements.

Now, I have some strut2 ActionSupport subclasses which do something
like this in my execute() method
       ThingDao thingDao= (ThingDao )getBean("ThingDao");  


All is well, all is working.

However, what I want to know is something about how Spring
works. Does it manage these beans as singletons? Or every time the
execute() method is called, and I get my dao bean, does it
instantiate a new instance of the dao bean object? Should I save
this dao bean object in a private member of my ActionSupport class
and reuse it everytime execute() is called?

Right now, I have my ActionSupport class execute method make the
getBean everytime execute is called.

At what point does Spring get a database connection...when the dao
bean is instantiated, or when the dao bean executes() some jdbc
call. (I assume this is when it makes a jdbc call, but I just want
to confirm).

If anyone can enlighten me or point me to some good documentation on
this subject, I would appreciate it.

Thanks,
Cecilia

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.