On 15-11-2008 at 15:54, Abhi 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?

I like your Interceptor approach; it's exactly the way to do dependency
injection in action beans. I wonder though: is Spring really not an
option? There's no reason to reinvent the wheel.


Oscar

-- 
   ,-_   The more laws, the less justice.
  /() )
 (__ (    -- Marcus Cicero - "De Officiis" (44 B.C.)
=/  ()

-------------------------------------------------------------------------
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

Reply via email to