Search code examples
jax-wsjndiglassfish-3ejb-3.1

@EJB injection fails but JNDI lookup works in web service class in Glassfish


I have a @WebService class that injects an @EJB. The EJB is packaged in a .jar file which is in the same .war file as the web service classes. The @EJB injection always fails, but I can do a JNDI lookup on the EJB. I've tried making the EJB and its interface @Remote, but that didn't matter. Injection still fails and JNDI lookup still works.

I'm using a version 3.0 web.xml. There's no ejb deployment descriptor in the ejb.jar file, but that is not suppose to matter in EJB 3.1.

An I missing something or is this a bug in Glassfish?

Here's my code.

EJB class and interface packaged in a .jar in the .war file:

//@Remote
public interface ReportServiceI {

    public String testAlive();
}

@Stateless
//@Remote (ReportServiceI.class)
public class ReportService implements ReportServiceI {...}

Web service class:

@WebService(
  targetNamespace = "http://www.reps.corp.com/services/reports/ReportService", 
  portName="ReportPort",
  serviceName="ReportService", 
  endpointInterface="com.corp.reps.reports.ws.server.ReportServiceWSI")

public class ReportServiceWS implements ReportServiceWSI {

  public static Logger logger = Logger.getLogger(ReportServiceWS.class);

//  These all fail
//  @EJB
//  @EJB(beanInterface=ReportServiceI.class)
//  @EJB(lookup="java:global/repsreports/ReportService")
  ReportServiceI reportService;

  public String testAlive() {

    //  this works
    try {
      InitialContext context = new InitialContext();
      reportService = (ReportServiceI)context.lookup("java:global/repsreports/ReportService");
    }
    catch (NamingException ex) {
      logger.error(ex);

      return "InitialContext.lookup() failed.";
    }

Solution

  • This is a bug in Glassfish (apparently in the web services stack).