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

﹥>﹥吖頭↗ 提交于 2019-12-12 12:24:57

问题


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.";
    }

回答1:


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




回答2:


Piotr,

No to both.

beans.xml is a CDI file and I'm using Glassfish as the injection container. I'll try making the @WebService bean @stateless - it's about the only thing I haven't tried - but that shouldn't be necessary.

(This forum software won't allow me to add a comment below Piotr's.)



来源:https://stackoverflow.com/questions/9426322/ejb-injection-fails-but-jndi-lookup-works-in-web-service-class-in-glassfish

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!