@EJB注入失败,但是JNDI查找在Glassfish的Web服务类中起作用 [英] @EJB injection fails but JNDI lookup works in web service class in Glassfish

查看:88
本文介绍了@EJB注入失败,但是JNDI查找在Glassfish的Web服务类中起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个@WebService类,它注入一个@EJB。 EJB打包在一个.jar文件中,该文件与Web服务类位于同一.war文件中。 @EJB注入总是失败,但是我可以在EJB上进行JNDI查找。我尝试过制作EJB及其接口@Remote,但这没关系。注入仍然失败,并且JNDI查找仍然有效。

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.

我正在使用3.0版的web.xml。 ejb.jar文件中没有ejb部署描述符,但是在EJB 3.1中这并不重要。

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.

我丢失了某些东西,或者这是Glassfish中的错误吗?

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

这是我的代码。

EJB类和接口打包在.war文件的.jar中:

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服务类别:

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


推荐答案

这是在Glassfish中的错误(显然是在Web服务堆栈中)。

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

这篇关于@EJB注入失败,但是JNDI查找在Glassfish的Web服务类中起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆