Question

I know it is possible to use ServiceTracker to inject OSGi services to EJBs.

However, how should I use OSGi Blueprint XML configuration to inject services to standard EJBs, so that services would be available when EJBs are used elsewhere? Or is it really impossible, as EJBs work in a layer of their own?

I've been trying to do this with Aries Blueprint as well as Gemini Blueprint, with JBoss AS7, without luck.

As an example bean:

import javax.annotation.PostConstruct;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import org.osgi.framework.BundleContext;

@Stateless
@LocalBean
public class SimpleStatelessSessionBean {

  InformationService service; // how'd I go about to get this populated?

  @PostConstruct
  public void init() {

  }

  public String getMessage() {

    if (service == null)
      throw new IllegalStateException("Service not available");

    return "EJB:" + service.getMessage();
  }
}
Was it helpful?

Solution

It seems what I asked is not really possible.

What is possible is

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top