我在 REST 服务中注入 EJB 时遇到问题(在 glassfish 3.2 服务器上使用球衣),我很困惑。
我有一个 EJB 接口声明为:
import javax.ejb.Local;
@Local
public interface TestServiceLocal {
public String getText();
}
以及实现它的类bean:
import javax.ejb.Local;
import javax.ejb.Stateless;
/**
* Session Bean implementation class TestService
*/
@Stateless
@Local(TestServiceLocal.class)
public class TestService implements Serializable, TestServiceLocal {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public TestService() {
// TODO Auto-generated constructor stub
}
@Override
public String getText() {
return this.getClass().getName();
}
}
REST 服务如下所示:
@Path("/service")
@Stateless
public class TestRestService {
@EJB(beanName="TestService")
private TestServiceLocal testService;
public TestRestService () {
}
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/events")
public String getText() {
return testService.getText();
}
}
问题是当调用 REST 服务时,无法创建 bean:
SEVERE: EJB5070: Exception creating stateless session bean : [TestRestService]
WARNING: EJB5184:A system exception occurred during an invocation on EJB TestRestService, method: public java.lang.String TestRestService.getText()
WARNING: javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:454)
at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2547)
at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1899)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at com.sun.proxy.$Proxy839.getText(Unknown Source)
我已经看过这里发布的答案,但似乎没有一个对我有用。任何帮助将不胜感激。谢谢!
PS:我忘了提到(不知道是否相关)。我的项目是在 eclipse Juno 下作为动态 Web 项目创建的。