users@glassfish.java.net

RE: OSGi - _at_EJB injection of an internal _at_Singleton

From: Robert Weeks <RWeeks_at_ext-inc.com>
Date: Mon, 20 Jun 2011 10:54:57 -0700

Hey Sahoo -

We are not using WAB's at all - this is all in the bundle and our servlets are registered via HttpService.

I knew the servlets that are registered via that cannot get the injections - and forgot - sorry - bad reference.

And I did verify it does work as advertised - say if we create an MDB inside our bundle and inject the Singleton via @EJB it grabs it OK.

Thanks for your reply.


Robert Weeks
Lead Developer - Framework and UI
EXTENSION, INC.
Email: rweeks_at_ext-inc.com
Office: 260-797-0200 x4228
General: 877-207-3753
www.OpenTheRedBox.com

Download the FREE EXTENSION Mobile App for iPhone and iPod Touch
http://www.opentheredbox.com/iPhone_appDemo.php

________________________________________
From: Sahoo [sanjeeb.sahoo_at_oracle.com]
Sent: Monday, June 20, 2011 1:09 PM
To: users_at_glassfish.java.net
Cc: Robert Weeks; users_at_glassfish.dev.java.net
Subject: Re: OSGi - @EJB injection of an internal @Singleton

Hi Robert,

I am sure you know @EJB can only be used in Java EE managed classes like
Servlets, EJBs, etc., so don't expect it to work if you accidentally
used it in regular classes. I am surprised that it is not even working
for you from a Servlet. May I know how you packaged your bundle? Where
are the EJB and Servlet classes. I am assuming it is a WAB, because it
has both EJB and Servlet. If you have packaged it as a WAB (by
definition a WAB must have Web-ContextPath header), then I don't see the
need to have Export-EJB header at all unless you want the EJBs to be
really exported as service. When the WAB gets deployed, the EJBs will
automatically get deployed. If you send me the log messages that appear
after you deploy this bundle, I can look into it to see what's going on.

Thanks,
Sahoo
On Monday 20 June 2011 09:46 PM, Robert Weeks wrote:
> Hello -
>
> We are trying to have a Singleton inside of a bundle - and have a class/servlet inside that bundle reference that singleton via @EJB - but are not getting the results we are wanting/needing.
>
> If we define a @Singleton within the bundle:
>
> package com.mycompany.classes;
>
> @Singleton
> public class MySingleton {
> ....
>
>
> and within that same bundle - have another class to reference that singleton
>
> @EJB
> private MySingleton mySingleton;
>
>
> Always comes up null.
>
> We have tried to export - but not sure if we are missing something.
>
> In manifest:
>
> Export-EJB: All;
> Export-EJB: om.mycompany.classes.MySingleton;
>
> etc.
>
> Are we missing something here?
>
> Thanks for any information.
>
>