In the "Yet another DI framework" category, I developped, for my own
needs, something to make standard JEE annotations (@EJB, @Resource,
@PersistenceContext) work on unmanaged beans like Stripes actions or
JUnit tests.

Once the interceptor is set up, I would add to my Action bean:
@Resource(mappedName="comp:/env/jdbc/MyDS")
DataSource dataSource;

Helas, I do not handle resource closing at the moment.

It is located here:
http://beanjector.sourceforge.net/
Source code is in the SVN repository with a sample Stripes application.

Gérald


2008/11/18 Abhi <[EMAIL PROTECTED]>:
> Thanks for all the inputs guys.
>
> On Mon, Nov 17, 2008 at 10:26 AM, Gregg Bolinger
> <[EMAIL PROTECTED]> wrote:
>>
>> I'd just like to point out that Spring isn't the only DI framework on the
>> block. So I don't think it should be inevitable that one makes the choice
>> for Spring.  Don't get me wrong, Spring is great.  But Guice is also great
>> and used along with warp-persist[1], it can be just as good, IMHO, if you
>> are only using Spring for DAO/Service layers and transactional support.
>>
>> [1]http://www.wideplay.com/guicewebextensions2
>>
>> Gregg
>>
>> On Sun, Nov 16, 2008 at 2:49 PM, Chris Herron <[EMAIL PROTECTED]> wrote:
>>>
>>> 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
>>>
>>
>>
>> -------------------------------------------------------------------------
>> 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
>>
>
>
>
> --
> 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

Reply via email to