Skip to main content

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2009-07-19

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-03-30

Depending on when the ServiceEvent is raised, the looked up EJB
reference may or may not be in a valid reference. If the EJB has been
undeployed, which happens on Bundle.STOPPING state, then the reference
becomes invalid. What's wrong if you look up every time you need the EJB?

Have you looked at GlassFish's support for EJB as OSGi service? It
automatically makes available stateless EJBs with local business
interfaces as OSGi services.


On Thursday 02 June 2011 12:37 PM, wrote:
> Hi,
> (I use glassfish 3.1, GA build)
> I have a ServiceListener class that needs to access EJB bean located
> in the
> same bundle. I noticed that it works only if ServiceListener makes EJB
> lookup
> on every event it gets.
> If I lookup EJB in ServiceListener constructor, when I try to access
> it in
> serviceChanged(), I get an exception "Attempt to invoke when container
> is in
> Undeployed."
> Here is the working version of code: public class MyServiceListener
> implements ServiceListener { private MyServiceBean adminService; public
> synchronized void serviceChanged(ServiceEvent event) { switch
> (event.getType()) { case ServiceEvent.REGISTERED: try {
> adminService = (MyServiceBean)
> new
> InitialContext().lookup("java:global/com.ex.test-war/adminServiceBean");
> } catch (NamingException e) {
> logger.error("exception: ",e);
> }
> ... do something
> adminService.installService(serviceName);
> break; }
> } }
> If I move the try-catch code to ServiceListener constructor, I get an
> exception in serviceChanged.
> Is it a known bug? Am I doing something wrong?
> thanks
> --
> [Message sent by forum member 'okna2000']
> View Post: