Spring reference for setting up Hibernate, datasources etc:
http://static.springframework.org/spring/docs/2.5.x/reference/orm.html
On Nov 16, 2008, at 3:45 PM, Chris Herron wrote:
Abhi,
Standalone unit testing is easy - with the right setup. People
typically run into problems when their code explicitly relies on
container-provided services such as datasources, transaction
management etc. If you abstract the access to those services, then
you can provide alternative implementations when running outside of
a container. Spring does a lot of that for you - it can configure
and manage your DataSource and Hibernate SessionFactory. If
necessary, you can provide alternative configurations to your unit
tests.
With a Stripes (or Struts) web app, when its running in the servlet
container, you would usually configure the Spring
ContextLoaderListener to bootstrap the Spring application context.
For unit tests, you would initialize Spring programmatically.
Chris.
On Nov 16, 2008, at 2:42 AM, Abhi wrote:
Thanks for that Alex. I have a question regarding the usage of
Spring and Hibernate with Stripes.
If I use Spring, Hibernate and Stripes stack, can I test DB
persistence stand alone (As in from a main method)? I have used
struts(1.2), Spring and Hibernate stack before and there was no way
(or maybe I did not know of one) I could test stand alone.
On Sat, Nov 15, 2008 at 3:54 PM, Abhi <[EMAIL PROTECTED]>
wrote:
I have to acess a Database Connection object in my action bean. I
am using plain old vanilla JDBC(no Spring and Hibernate). I am
setting the DataSource object in ServletContext on application
initialization and using this DataSource object to get a DB
Connection object whenever I want.
One approach that I can take is to get the Connection object
directly from the ServletContext in my method and use it. But the
problem with this approach is that I can't test my action bean
stand alone (as the Connection object is taken from the
ServletContext).
To over come this I have provided a setter and getter for
Connection in my action bean and I use an Interceptor to inject the
Connection object into my bean before HandlerResolution life cycle
stage. The advantage of this is, now I can test my bean stand alone
by setting my own Connection object and when it runs inside a
servlet container Stripes does the injection for me. To close the
connection also I am using an intercptor that closes the connection
after ResolutionExecution life cycle stage.
Is my approach correct or is there a better way to achieve what I
want?
--
Cheers,
Abhi
--
Cheers,
Abhi
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
Build the coolest Linux based applications with Moblin SDK & win
great prizes
Grand prize is a trip for two to an Open Source event anywhere in
the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users